You are on page 1of 2

#include <bits/stdc++.

h>
using namespace std;

int n, q, d[200005];

void make_set () {

for (int i = 1; i <= n; i++)


d[i] = i;
}

int find_set (int u) {

if (u == d[u])
return u;
return d[u] = find_set (d[u]);
}

void union_set (int u, int v) {

u = find_set (u);
v = find_set (v);

if (u == v)
return;

d[u] = v;
}

int main () {

ios_base::sync_with_stdio (false);
cin.tie (0);
cout.tie (0);
freopen ("restruct.inp", "r", stdin);
freopen ("restruct.out", "w", stdout);

cin >> n >> q;


make_set ();
//if ((n <= 1000) && (q <= 1000)) {

while (q--) {

int ktv, x, y;
cin >> ktv >> x >> y;

if (ktv == 1) {
union_set (x, y);
}

else {
if (ktv == 2) {
for (int i = x; i <= y; i++) {
union_set (i, x);
union_set (i, y);
}
}

else {
if (find_set (x) == find_set (y))
cout << "YES\n";
else
cout << "NO\n";
}
}

//union_set (x, y);


}
//}

return 0;
}
// bài này là restruct, bài này cũng chưa chấm nhá

You might also like