Pagini recente » Cod sursa (job #252557) | Cod sursa (job #2373527) | Cod sursa (job #1961442) | Cod sursa (job #716991) | Cod sursa (job #1220981)
#include<fstream>
using namespace std;
int t[100007], x, y, x2, y2, n, m, i, op;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int rad(int x){
while(t[x]>0){
x=t[x];
}
return x;
}
int main(){
in>>n>>m;
for(i=1; i<=n; i++)
t[i]=-1;
for(;m--;){
in>>op>>x>>y;
x2=rad(x);
y2=rad(y);
if(op==1 && x2!=y2){
if(t[x2]<=t[y2]){
t[y]=x2;
t[x2]-=t[y2];
}
else{
t[x]=y2;
t[y2]-=t[x2];
}
continue;
}
if(op==2){
if(x2!=y2)
out<<"NU\n";
else
out<<"DA\n";
}
}
return 0;
}