cf/mirror

Nearest Leaf

CF
1110F2600· international gm4s512 MB⌨ stdin/stdout

Examples

Sample 1of 3
Input
5 3
1 10
1 1
3 2
3 3
1 1 5
5 4 5
4 1 2
Output
3
0
13
Sample 2of 3
Input
5 3
1 1000000000
2 1000000000
1 1000000000
1 1000000000
3 4 5
2 1 5
2 4 5
Output
3000000000
1000000000
2000000000
Sample 3of 3
Input
11 8
1 7
2 1
1 20
1 2
5 6
6 2
6 3
5 1
9 10
9 11
5 1 11
1 1 4
9 4 8
6 1 4
9 7 11
9 10 11
8 1 11
11 4 5
Output
8
8
9
16
9
10
0
34
1110F.cpp
loading editor…
Ln 11·137 BGNU C++20 (64)
loading graph engine…