Company: DeShaw_30june
Difficulty: medium
Count Perfect Route Cycles Problem Description A bus company runs services between stations numbered from 1 to tree_nodes . The existing routes form a tree : the network is connected, and between any two stations there is exactly one route path. The company operates in two regions. A station in the first region is coloured white ( 0 ), and a station in the second region is coloured black ( 1 ). You must add one new direct route between two distinct stations u and v . Because the network is a tree, adding that route creates exactly one cycle: the stations on the existing route path from u to v , closed up by the new route. The new route forms a perfect route cycle when both of the following hold: the cycle contains at least 3 stations , and every station on the cycle belongs to the same region -- all white, or all black. Count the number of distinct pairs of stations you could join so that a perfect route cycle is formed. Input Format Line 1: a single integer tree_nodes , the number of