Pagini recente » Cod sursa (job #2819543) | Cod sursa (job #2268818) | Istoria paginii runda/cvuri | Cod sursa (job #971164) | Cod sursa (job #2280462)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int const NLIM = 100000;
int daddy[NLIM],n,m;
int sef(int x){
if(x!=daddy[x])x=sef(daddy[x]);
return daddy[x];
}
void join(int x,int y){
int t1 = sef(x);
int t2 = sef(y);
daddy[t2]=t1;
}
bool query(int x,int y){
if(sef(x)==sef(y))return true;
return false;
}
void citire(){
unsigned int i;
fin>>n>>m;
for(i=1;i<=n;i++)daddy[i]=i;
for(i=1;i<=m;i++){
int cod,x,y;
fin>>cod>>x>>y;
if(cod==1)join(x,y);
else {
if(query(x,y)==true)fout<<"DA"<<endl;
else fout<<"NU"<<endl;
}
}
}
int main()
{
citire();
return 0;
}