cf/mirror

Tree Shuffling

CF
1363E2000· candidate master2s256 MB⌨ stdin/stdout

Examples

Sample 1of 3
Input
5
1 0 1
20 1 0
300 0 1
4000 0 0
50000 1 0
1 2
2 3
2 4
1 5
Output
4
Sample 2of 3
Input
5
10000 0 1
2000 1 0
300 0 1
40 0 0
1 1 0
1 2
2 3
2 4
1 5
Output
24000
Sample 3of 3
Input
2
109 0 1
205 0 1
1 2
Output
-1
1363E.cpp
loading editor…
Ln 11·137 BGNU C++20 (64)
loading graph engine…