#D7000. Weighted Union Find Trees
Weighted Union Find Trees
Weighted Union Find Trees
There is a sequence . You are given the following information and questions.
- relate: is greater than by
- diff: report the difference between and
Constraints
- There are no inconsistency in the given information
Input
:
In the first line, and are given. Then, information/questions are given in the following format.
0
or
1
where '0' of the first digit denotes the relate information and '1' denotes the diff question.
Output
For each diff question, print the difference between and .
Example
Input
5 6 0 0 2 5 0 1 2 3 1 0 1 1 1 3 0 1 4 8 1 0 4
Output
2 ? 10
inputFormat
Input
:
In the first line, and are given. Then, information/questions are given in the following format.
0
or
1
where '0' of the first digit denotes the relate information and '1' denotes the diff question.
outputFormat
Output
For each diff question, print the difference between and .
Example
Input
5 6 0 0 2 5 0 1 2 3 1 0 1 1 1 3 0 1 4 8 1 0 4
Output
2 ? 10
样例
5 6
0 0 2 5
0 1 2 3
1 0 1
1 1 3
0 1 4 8
1 0 4
2
?
10
</p>