#P2634. [国家集训队] 聪聪可可
[国家集训队] 聪聪可可
Description
Congcong and Keke are brothers who often fight over trivial things, such as when only one ice pop is left at home and they both want it, or they both want to use the computer (but there is only one). Normally they would resolve it with rock-paper-scissors, but they are bored of that simple game.
Their father, annoyed by their arguments, invented a new game: he draws “points” on paper and uses “edges” to connect them so that the “points” are connected (this is a tree). Each “edge” has a number on it. Then Congcong and Keke each randomly choose one point (they cannot see the tree when choosing). If the sum of the numbers on all edges along the path between the two chosen points is a multiple of , Congcong wins; otherwise, Keke wins.
Congcong likes thinking about problems. After each game, he carefully studies the tree and wants to know his winning probability for this graph. Please help compute this value to verify Congcong’s answer.
Input Format
The first line contains a positive integer . The next lines each contain integers , indicating there is an edge between node and node with number .
Output Format
Output the probability as an irreducible fraction in the form a/b, where and are coprime. If the probability is , output 1/1.
5
1 2 1
1 3 2
1 4 1
2 5 3
13/25
Hint
Sample Explanation:
There are ordered pairs: , , , , , , , , , , , , .
Constraints:
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号