Pagini recente » Cod sursa (job #159594) | Cod sursa (job #1897806) | Cod sursa (job #2840251) | Cod sursa (job #874425) | Cod sursa (job #2803836)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
const string msj[] = {"NU", "DA"};
const int DIM = 100005;
int n, m, tata[DIM];
int rad(int nod){
if(nod == tata[nod])
return nod;
return tata[nod] = rad(tata[nod]);
}
int main (){
fin>>n>>m;
for(int i=1; i<=n; i++)
tata[i] = i;
int op, x, y;
while(m--){
fin>>op>>x>>y;
if(op == 1)
tata[rad(y)] = rad(x);
else
fout<<msj[rad(x) == rad(y)]<<"\n";
}
return 0;
}