Pagini recente » Cod sursa (job #2856296) | Cod sursa (job #745661) | Cod sursa (job #1922508) | Cod sursa (job #140314) | Cod sursa (job #2335447)
#include <iostream>
#include <fstream>
using namespace std;
int v[100001];
int father[100001];
int main()
{
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n,m;
fin>>n>>m;
int p,a,b,c;
int i;
for(i=0;i<m;i++){
fin>>p>>a>>b;
if(p==1){
if(father[a]==0 && father[b]==0){
father[b]=a;
}
else{
while(father[a]!=0)
a=father[a];
while(father[b]!=0){
c=b;
b=father[b];
father[c]=a;
}
father[b]=a;
}
}
else{
while(father[a]!=0)
a=father[a];
while(father[b]!=0)
b=father[b];
if(a==b) fout<<"DA"<<endl;
else fout<<"NU"<<endl;
}
}
fin.close();
fout.close();
return 0;
}