Pagini recente » Cod sursa (job #1902013) | Cod sursa (job #3346140) | Cod sursa (job #3342318) | Cod sursa (job #1398494) | Cod sursa (job #3326244)
#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;
fin>>n>>m;
for(int i=1; i<=n; i++) t[i]=i;
while (m--){
int cod, x, y;
fin>>cod>>x>>y;
int rx=rad(x), ry=rad(y);
if(cod==1){
t[rx]=ry;
}
else if(cod==2){
if(rx==ry) fout<<"DA\n";
else fout<<"NU\n";
}
}
return 0;
}