cf/mirror

Weighting a Tree

CF
901D2700· international gm2s256 MB⌨ stdin/stdout

Examples

Sample 1of 4
Input
3 3
2 2 2
1 2
2 3
1 3
Output
YES
1
1
1
Sample 2of 4
Input
4 3
-1 0 2 1
1 2
2 3
3 4
Output
YES
-1
1
1
Sample 3of 4
Input
6 6
3 5 5 5 1 5
1 4
3 2
4 3
4 5
3 5
5 6
Output
YES
3
5
3
-1
-3
5
Sample 4of 4
Input
4 4
4 4 2 4
1 2
2 3
3 4
4 1
Output
NO
901D.cpp
loading editor…
Ln 11·137 BGNU C++20 (64)
loading graph engine…