#P3367. 【模板】并查集
【模板】并查集
Description
As stated, there is a disjoint set union (union-find). You need to perform union and query operations.
Input Format
The first line contains two integers , representing elements and operations.
The next lines each contain three integers .
When , union the sets containing and .
When , output whether and are in the same set. Output Y if yes; otherwise output N.
Output Format
For each operation with , output one line containing a single uppercase letter, either Y or N.
4 7
2 1 2
1 1 2
2 1 2
1 3 4
2 1 4
1 2 3
2 1 4
N
Y
N
Y
Hint
For of the testdata, , .
For of the testdata, , .
For of the testdata, , .
For of the testdata, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号