Pagini recente » Cod sursa (job #514957) | Cod sursa (job #2775638) | Cod sursa (job #1696506) | Cod sursa (job #2960888) | Cod sursa (job #2491796)
#include <cstdio>
using namespace std;
int t[100001], h[100001];
int FindFirstAncestor(int x) {
while(x != t[x])
x = t[x];
return x;
}
void Operation2(int x, int y) {
bool c = FindFirstAncestor(x) == FindFirstAncestor(y);
if(c)
printf("DA\n");
else
printf("NU\n");
}
void Operation1(int x, int y) {
if(h[x] == h[y]) {
t[y] = x;
h[x]++;
}
else if(h[x] > h[y]) {
t[y] = x;
}
else
t[x] = y;
}
int main() {
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w", stdout);
int i, n, m, op_type, x, y, tx, ty;
scanf("%d%d", &n, &m);
for(i = 1; i <= n; i++)
{
t[i] = i;
h[i] = 1;
}
for(i = 1; i <= m; i++)
{
scanf("%d%d%d", &op_type, &x, &y);
if(op_type == 2)
Operation2(x, y);
else
Operation1(x, y);
}
return 0;
}