cf/mirror

Yasya and the Mysterious Tree

CF
1980G2300· international master2.5s512 MB⌨ stdin/stdout

Examples

Sample 1of 2multi-test • hover to link
Input
2
3 7
1 2 1
3 1 8
^ 5
? 2 9
^ 1
? 1 10
^ 6
? 3 1
? 2 9
5 6
1 2 777
3 2 2812
4 1 16
5 3 1000000000
^ 4
? 3 123
? 5 1000000000
^ 1000000000
? 1 908070
? 2 1
Output
13 15 11 10
1000000127 2812 999756331 999999756
Sample 2of 2multi-test • hover to link
Input
3
8 4
8 6 3
6 3 4
2 5 4
7 6 2
7 1 10
4 1 4
5 1 2
^ 4
^ 7
? 7 8
? 4 10
5 6
3 1 4
2 3 9
4 3 6
5 2 10
? 5 7
^ 1
^ 8
? 4 10
? 1 9
? 3 6
4 2
2 1 4
4 3 5
2 3 4
^ 13
? 1 10
Output
14 13
13 8 11 11
10
1980G.cpp
loading editor…
Ln 11·137 BGNU C++20 (64)
loading graph engine…