Pagini recente » Cod sursa (job #1131389) | Cod sursa (job #1121186) | Cod sursa (job #60882) | Cod sursa (job #810924) | Cod sursa (job #1922528)
# include <cstdio>
using namespace std;
FILE *f = freopen("disjoint.in", "r", stdin);
FILE *g = freopen("disjoint.out", "w", stdout);
const int N_MAX = 100010;
int n, m;
int tata[N_MAX];
int group(int node){
int copie = node;
while (tata[copie]){
copie = tata[copie];
}
while (tata[node]){
int aux = node;
node = tata[node];
tata[aux] = copie;
}
return copie;
}
void unite(int x, int y){
int g1 = group(x);
int g2 = group(y);
tata[g1] = g2;
}
void read(){
scanf("%d %d", &n, &m);
for (int i=1; i<=m; i++){
int x, y, z;
scanf("%d %d %d", &z, &x, &y);
if (z == 1){
unite(x, y);
}
else{
if (group(x) == group(y)){
printf("DA\n");
}
else
printf("NU\n");
}
}
}
int main(){
read();
return 0;
}