#P3402. 【模板】可持久化并查集
【模板】可持久化并查集
Description
Given sets, the -th set initially contains only the element .
There are operations, of three types:
1 a bMerge the sets containing and ;2 kRevert to the state right after the -th operation (any of the three types counts as one operation). It is guaranteed that at least operations have already been performed (not counting this one). In particular, if , revert to the initial state;3 a bQuery whether and belong to the same set; if yes, output , otherwise output .
Input Format
The first line contains two integers and .
Then follow lines. On each line, first read an integer . If then read an integer ; otherwise read two integers , describing one operation.
Output Format
For each operation of type , output one line with one integer indicating the answer.
5 6
1 1 2
3 1 2
2 0
3 1 2
2 1
3 1 2
1
0
1
Hint
For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号