Pagini recente » Cod sursa (job #1282671) | Cod sursa (job #2741782) | Cod sursa (job #1373841) | Cod sursa (job #1862043) | Cod sursa (job #1439137)
#include <fstream>
using namespace std;
int n,m,v[100001],i,op,x,y;
int stramos(int x){
if(v[x]==x) return x;
else return stramos(v[x]);
}
int main(){
ifstream in("disjoint.in");
ofstream out("disjoint.out");
in>>n>>m;
for(i=1;i<=n;i++) v[i]=i;
for(i=1;i<=m;i++){
in>>op>>x>>y;
if(op==1) v[y]=v[x];
else if(stramos(x)==stramos(y)) out<<"DA"<<'\n';
else out<<"NU"<<'\n';
}
in.close();
out.close();
return 0;
}