Pagini recente » Cod sursa (job #1883868) | Cod sursa (job #164872) | Cod sursa (job #2728069) | Cod sursa (job #2194449) | Cod sursa (job #1258561)
#include <cstdio>
using namespace std;
#define nMax 100005
int T[nMax], R[nMax];
int N, M;
int find(int x){
for(; x != T[x]; x = T[x])
T[x] = T[T[x]];
return x;
}
void join(int u, int v){
if(R[u] > R[v])
T[v] = u;
else
T[u] = v;
if(R[u] == R[v])
R[v] ++;
}
int main(){
int x, y, type, u, v;
scanf("%d %d", &N, &M);
for(int i = 1; i <= N; ++ i)
T[i] = i, R[i] = 1;
while(M--){
scanf("%d %d %d", &type, &x, &y);
u = find(x);
v = find(y);
if(type == 1 && u != v)
join(u, v);
else if(type == 2)
puts((u != v) ? "NU" : "DA");
}
return 0;
}