Pagini recente » Cod sursa (job #610928) | Cod sursa (job #1647824) | Cod sursa (job #2752724) | Cod sursa (job #457633) | Cod sursa (job #1836060)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n, m, t[100001], h[100001];
int main()
{
int i, op, x, y;
fin>>n>>m;
for(i = 1; i <= m; i++){
fin>>op>>x>>y;
if(op == 1){
while(t[x]){
x = t[x];
}
while(t[y]){
y = t[y];
}
if(h[x] < h[y]){
t[x] = y;
h[y]++;
} else {
t[y] = x;
h[y]++;
}
} else{
while(t[x])
x = t[x];
while(t[y])
y = t[y];
if(x == y)
fout<<"DA"<<'\n';
else fout<<"NU"<<'\n';
}
}
}