Pagini recente » Cod sursa (job #2461349) | Cod sursa (job #832759) | Cod sursa (job #2383924) | Cod sursa (job #1445134) | Cod sursa (job #2576390)
#include <iostream>
#include <fstream>
#include <map>
#define NMAX 100005
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int papa[NMAX],n,x,y,t;
int nume[NMAX],nrtag=0;
map <int,int> c;
int root(int x){
if(papa[x] == x)
return x;
papa[x] = root(papa[x]);
return papa[x];
}
int main()
{
fin>>n;
for(int i = 1; i <= n; i++){
fin >> t >> x >> y;
if(c.find(x) == c.end()){
nrtag++;
c[x] = nrtag;
papa[nrtag] = nrtag;
}
if(c.find(y) == c.end()){
nrtag++;
c[y] = nrtag;
papa[nrtag] = nrtag;
}
if(t == 2){
papa[root(c[x])] = root(c[y]);
} else{
if(root(c[x]) == root(c[y])){
fout << "DA";
} else{
fout<<"NU";
}
}
}
return 0;
}