#P3637. 方程组
方程组
Description
Initially, xht has variables, denoted by . There is also a constant , and equations, each of the form .
Since the problem may change, xht sometimes needs to add a new equation or delete an existing one.
At the same time, xht will give you some queries: set the variable , and find the value of another variable . Of course, sometimes cannot be determined due to insufficient conditions; in that case, output .
The testdata guarantees that at any time there is at most one equation between any two variables. It is guaranteed that no contradictory systems will appear, and no redundant conditions will appear (no equation can be derived from some others).
Description
Input Format
The first line contains four integers , as described above. is the number of operations.
The next lines each contain three integers , representing the equation .
The next lines, each starting with an integer indicating the type of operation:
- : followed by , meaning to add an equation ;
- : followed by , meaning to delete the equation between and . If this equation does not exist, do nothing;
- : followed by , meaning a query: set , and ask for the value of .
Output Format
For each operation of type (query), output one integer (), representing . If the conditions are insufficient, output .
3 2 100 3
1 2 1
2 3 2
3 1 3 0
2 1 2
3 1 3 0
97
-1
Hint
Explanation of the sample:
Initially there are two equations: , .
In the first query, set , and obtain .
In the second query, the second equation has been deleted, leading to insufficient conditions, so cannot be determined. Output .
For of the testdata, there are only query operations.
For of the testdata, , , , , .
It is guaranteed that all .
Translated by ChatGPT 5
京公网安备 11011102002149号