cf/mirror

Again Trees... (hard version)

CF
2194F23000· legendary gm1s1024 MB⌨ stdin/stdout

Examples

Sample 1of 1multi-test • hover to link
Input
4
5 1
1 2
1 3
3 4
2 5
0 2 2 3 3
1
5 1
4 5
1 2
3 1
3 5
0 0 2 0 2
0
5 2
1 2
1 3
3 4
2 5
0 2 2 3 3
1 3
4 1
1 2
2 3
3 4
1 1 1 1
1
Output
2
8
4
3
2194F2.cpp
loading editor…
Ln 11·137 BGNU C++20 (64)
loading graph engine…