On a tree, count alternating left/right paths from a fixed start where each vertex is used once; report the maximum over all starting vertices.
Hard8TreeDFSDynamic programmingCombinatoricsNo attempts yetTime limit1sMemory limit512 MBYeongwoo drew a big tree on the schoolyard while studying. A tree is a connected graph with no cycle. Yeongseon walked past, noticed that the number of vertices is exactly her shoe size, and Yeongwoo offered her a game.
The rules go like this. Yeongseon picks one vertex and starts on it with her left foot down. From then on she moves along an edge to a neighbouring vertex, putting down her left foot and her right foot in turn. A vertex she has already stepped on is wiped off the ground by her footprint, so she cannot step on it again. When no vertex is left to move to, the game ends, and if the foot standing on that vertex is the left one Yeongseon wins, while the right one gives the win to Yeongwoo. If the tree has a single vertex, the game ends the moment it starts, and the left foot is down, so Yeongseon wins.
The schoolyard is so large that Yeongseon has to point at a starting vertex while knowing nothing about the tree. She thought the game was rigged against her and refused to play, so Yeongwoo decided to bait her by announcing the number of ways she wins when starting at some vertex x. Two ways count as different when the sequences of vertices she steps on differ. Yeongwoo wants to name a value as large as possible. You know the whole tree, so compute that value: the maximum, over every choice of the starting vertex, of the number of ways Yeongseon wins.

Suppose the tree drawn on the ground is the one above. Starting at vertex 1 with the left foot, Yeongseon wins in 2 ways: (1 left -> 2 right -> 4 left) and (1 left -> 2 right -> 5 left). Starting at vertex 2 with the left foot, she wins in 1 way: (2 left -> 1 right -> 3 left).
The first line contains the number of vertices N. (1≤N≤1,000,000)
Each of the next N−1 lines contains two integers a and b. (1≤a,b≤N) They mean that vertex a and vertex b are joined by an edge. The given graph is always a tree.
Print, on one line, the number of winning ways at a starting vertex where that number is largest.