Pagini recente » Cod sursa (job #1755626) | Cod sursa (job #80947) | Cod sursa (job #2030357) | Cod sursa (job #1053867) | Cod sursa (job #2750617)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("disjoint.in");
ofstream g ("disjoint.out");
int n,m;
int comp[100005];
int caut(int x) {
if(comp[x]==x) return x;
comp[x]=caut(comp[x]);
return comp[x];
}
void un(int x,int y) {
comp[caut(x)]=caut(y);
}
int main () {
f >> n >> m;
for(int i=1; i<=n; i++)
comp[i] = i;
for(int i=1; i<=m; i++) {
int op,x,y;
f >> op >> x >> y;
if(op == 1) {
un(x,y);
}
else {
if(caut(x)==caut(y))
g << "DA\n";
else
g << "NU\n";
}
}
return 0;
}