Pagini recente » Clasament abcdfegh | Cod sursa (job #2090509) | Cod sursa (job #245394) | Cod sursa (job #49490) | Cod sursa (job #1983456)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in ("disjoint.in");
ofstream out ("disjoint.out");
int n ;
int const nmax = 100000;
int x[5 + nmax];
int jump(int a){
if(a == x[a])
return a;
else{
x[a] = jump(x[a]);
return x[a];
}
}
int main()
{
int m;
in>>n>>m;
for(int i = 1 ; i <= n ;i++){
x[i] = i;
}
int p , a ,b;
int temp = 0 ,temp2 = 0;
for(int i = 0 ; i < m ;i++){
in>>p>>a>>b;
if(p == 1){
temp = jump(a);
temp2 = jump(b);
x[temp2] = temp;
} else if(p == 2){
temp = jump(a);
temp2 = jump(b);
if(temp == temp2)
out<<"DA\n";
else
out<<"NU\n";
}
}
return 0;
}