第一行n,m表示有n个节点,m个操作
接下来m行,每行一个操作
保证必定为link cut或者distance?
m <= 300000,所有关于边长的计算在int范围内
n <= 100000
有可能有重边(有可能权值一样的重边)
有可能link自环,此时输出failed
有可能询问两个相同的点的最短路,此时输出0
n <= 100000
样例输入1
5 12
link 1 2 3
link 2 3 3
distance? 1 3
cut 2 3 3
distance? 1 3
cut 2 3 2
link 2 3 2
cut 2 3 3
link 3 4 3
link 4 1 5
link 1 3 8
link 2 4 7
样例输入2
6 25
link 1 2 3
link 1 2 2
link 1 2 5
cut 1 2 2
cut 1 2 5
link 1 2 3
link 1 2 3
cut 1 2 3
cut 1 2 3
cut 1 2 3
cut 1 2 3
link 1 2 4
link 1 3 5
distance? 2 3
link 2 4 1
link 3 4 2
link 2 3 3
link 1 4 7
link 1 4 7
cut 1 4 7
link 5 6 8
distance? 3 6
distance? 2 6
cut 2 4 1
distance? 1 5
样例输出1
ok
ok
6
ok
-1
failed
ok
failed
ok
ok
ok
failed
样例输出2
ok
ok
ok
ok
ok
ok
ok
ok
ok
ok
failed
ok
ok
9
ok
ok
ok
failed
failed
failed
ok
-1
-1
ok
-1