#ds403. 带权并查集
带权并查集
Weighted Union-Find
Problem Description
You are given variables whose values are initially unknown.
You must perform operations:
1 l r x: gives a clue that . If this contradicts the known information, ignore this operation.2 l r: answer . If the current clues do not allow deducing the answer, ignore this operation.
Input Format
The first line contains two integers and (, ).
The following lines each describe one operation. The input is encrypted as follows:
There is a variable initially . After every query operation that is not ignored, becomes the absolute value of the answer, i.e. . Each operation's input gives encrypted ; the actual values are and .
It is guaranteed that and .
Output Format
For each query operation that is not ignored, output its answer. If a query operation is ignored, output nothing for it.
Sample Input
3 5
1 1 2 1
2 1 3
1 2 3 1
2 1 3
2 1 3
Sample Output
2
-1