Pagini recente » Borderou de evaluare (job #2044918) | Borderou de evaluare (job #2758467) | Borderou de evaluare (job #1255485) | Borderou de evaluare (job #2534273) | Cod sursa (job #2501349)
#include <iostream>
#include <fstream>
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(x);
}
void union1(int x,int y){
int sefx=find1(x),sefy=find1(y);
tata[sefy]=sefx;
}
using namespace std;
int main()
{
int n,m,i,x,y,op;
fin>>n>>m;
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;
}