Pagini recente » Cod sursa (job #1158239) | Cod sursa (job #1056596) | Cod sursa (job #2287676) | Cod sursa (job #1790861) | Cod sursa (job #2947083)
#include <iostream>
#include <fstream>
#define N 1000001
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout("disjoint.out");
int n, m, t[N];
void Union(int x, int y){
t[x] = y;
}
int Root(int x){
int tata, root = x;
while (t[root] != 0){
root = t[root];
}
while (x != root){
tata = t[x];
t[x] = root;
x = tata;
}
return root;
}
int main(){
fin >> n >> m;
int x, y, task;
for (int i = 0; i < m; ++i){
fin >> task >> x >> y;
x = Root(x);
y = Root(y);
if (task == 1){
Union(x, y);
}
else{
if (x == y)
fout << "DA\n";
else
fout << "NU\n";
}
}
return 0;
}