Pagini recente » Cod sursa (job #1307873) | Cod sursa (job #2345027) | Cod sursa (job #1757735) | Cod sursa (job #440734) | Cod sursa (job #2424561)
#include <iostream>
#include <fstream>
using namespace std;
int t[100001], nr [100001];
int tFind (int x) {
return (x == t[x]) ? x : (t[x] = tFind(t[x]));
}
int main()
{
//ifstream in ("date.in");/*
ifstream in ("disjoint.in");
ofstream out ("disjoint.out");//*/
int n, m, x, y, o, i;
in >> n >> m;
for (i = 1; i <= n; ++i) {t[i] = i; nr[i] = 1;}
for (i = 0; i < m; ++i) {
in >> o >> x >> y;
x = tFind(x);
y = tFind(y);
if (o == 1) {
if(nr[x] > nr[y]) {
nr[x] += nr[y];
t[y] = x;
}
else {
nr[y] += nr[x];
t[x] = y;
}
}
else {
out << ((x == y) ? "DA\n" : "NU\n");
}
}
return 0;
}