Pagini recente » Cod sursa (job #1027612) | Cod sursa (job #1890790) | Cod sursa (job #2396184) | Cod sursa (job #2212805) | Cod sursa (job #2817325)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int t[100001];
int sef(int x){
if (t[x]==x)
return x;
else
return sef(t[x]);
}
void unire(int x,int y){
t[sef(y)]=sef(x);
}
int main(){
int n,m,i,x,y,op;
fin>>n>>m;
for (i=1;i<=n;i++)
t[i]=i;
for (i=1;i<=m;i++){
fin>>op>>x>>y;
if (op==1)
unire(x,y);
else if (sef(x)==sef(y))
fout<<"DA"<<endl;
else
fout<<"NU"<<endl;
}
return 0;
}