Pagini recente » Cod sursa (job #738402) | Cod sursa (job #3265259) | Cod sursa (job #682619) | Cod sursa (job #1053618) | Cod sursa (job #2611933)
#include <cstdio>
int t[505], rang[505];
int root(int x) {
if(t[x] == 0)
return x;
else {
int temp = root(t[x]);
t[x] = temp;
return temp;
}
}
void join(int x, int y) {
int rootX = root(x), rootY = root(y);
if(rang[x] > rang[y])
t[rootY] = rootX;
else {
t[rootX] = rootY;
if(rang[x] == rang[y])
++rang[y];
}
}
int main() {
int n, m, i, c, x, y;
scanf("%d%d", &n, &m);
for(i = 1; i <= m; ++i) {
scanf("%d%d%d", &c, &x, &y);
if(c == 1)
join(x, y);
else
if(root(x) == root(y))
printf("DA\n");
else
printf("NU\n");
}
}