Pagini recente » Cod sursa (job #416250) | Cod sursa (job #1925610) | Cod sursa (job #2827204) | Cod sursa (job #533359) | Cod sursa (job #2503917)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int tata[100001];
int find1(int x){
if(tata[x]==x)
return x;
else
return tata[x]=find1(tata[x]);
}
void union1(int x,int y){
int sefx=find1(x),sefy=find1(y);
if(x<y)
tata[sefy]=sefx;
else
tata[sefx]=sefy;
}
int main()
{
int n,m,i,x,y,op;
fin>>n>>m;
for(i=1;i<=n;i++)
tata[i]=i;
for(i=1;i<=m;i++){
fin>>op>>x>>y;
if(op==1)
union1(x,y);
else{
if(find1(x)==find1(y))
fout<<"DA"<<"\n";
else
fout<<"NU"<<"\n";
}
}
return 0;
}