Loading environment...
Santa’s North Pole road network is a TREE with festive lights:
A route between two towns and is the unique path between them in the tree. Santa calls a route a "candy cane" if the road colors strictly alternate along that path (e.g., R, G, R, G or G, R, G, R). No two consecutive roads on the route are allowed to have the same color of lights.
Santa wants to know:
How many pairs of towns are connected by a candy cane path?
You must count all unordered pairs of towns where , such that the unique path between town and town is a candy cane.
u v c:
'R' (Red) or 'G' (Green).Output a single integer representing the number of unordered pairs such that the path between and is a candy cane.
No comments yet. Be the first to comment!