Pagini recente » Monitorul de evaluare | Cod sursa (job #3363421) | Cod sursa (job #3362163) | Cod sursa (job #3361756) | Cod sursa (job #3362137)
#include <iostream>
#include <fstream>
using namespace std;
const int N=1e5+5;
int dsu[N],n,q;
int t(int nod){
if(!dsu[nod]||dsu[nod]==nod)return nod;
return dsu[nod]=t(dsu[nod]);
}
int main()
{
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
fin>>n>>q;
int x,c,y;
while(q--){
fin>>c>>x>>y;
x=t(x);
y=t(y);
if(c==1){
dsu[y]=x;
}
else{
if(x==y)fout<<"DA\n";
else fout<<"NU\n";
}
}
fin.close();
fout.close();
return 0;
}