Pagini recente » Cod sursa (job #3350834) | Cod sursa (job #1782779) | Monitorul de evaluare | Cod sursa (job #3333131) | Cod sursa (job #3326243)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int maxsize=1e5+4;
int t[maxsize];
int rad(int x){
if(x==t[x])
return x;
t[x]=rad(t[x]);
return t[x];
}
int main()
{
int n, m;
cin>>n>>m;
for(int i=1; i<=n; i++) t[i]=i;
while (m--){
int cod, x, y;
cin>>cod>>x>>y;
int rx=rad(x), ry=rad(y);
if(cod==1){
t[rx]=ry;
}
else if(cod==2){
if(rx==ry) cout<<"DA\n";
else cout<<"NU\n";
}
}
return 0;
}