Pagini recente » Cod sursa (job #3231610) | Cod sursa (job #2341110) | Cod sursa (job #1960349) | Cod sursa (job #909570) | Cod sursa (job #2614194)
#include <bits/stdc++.h>
using namespace std;
ifstream ci("disjoint.in");
ofstream cou("disjoint.out");
int t[100005],n,m;
int Find(int x){
int r=x,r1;
while(t[r]){
r=t[r];
}
while(t[x]){
r1=t[x];
t[x]=r;
x=r1;
}
return r;
}
void Union(int x,int y){
t[y]=x;
}
void rez(){
ci>>n>>m;
int i,c,x,y;
for(i=1;i<=m;i++){
ci>>c>>x>>y;
x=Find(x);
y=Find(y);
if(c==1){
Union(x,y);
}else{
if(x==y){
cou<<"DA \n";
}else{
cou<<"NU \n";
}
}
}
}
int main()
{
rez();
return 0;
}