Pagini recente » Clasament preoli9 | Cod sursa (job #1397302) | Cod sursa (job #2074244) | Cod sursa (job #2048147) | Cod sursa (job #2473871)
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n,m,tata[maxn];
int tata_suprem(int nod)
{
if(tata[nod]==0)
return nod;
return tata_suprem(tata[nod]);
}
void unim(int A,int B)
{
A=tata_suprem(A);
B=tata_suprem(B);
srand(69);
int x=rand()%2;
if(x==1)
tata[A]=B;
else
tata[B]=A;
}
int main()
{
fin>>n>>m;
for(int i=1;i<=m;i++)
{
int cod,x,y;;
fin>>cod>>x>>y;
if(cod==1)
{
unim(x,y);
}
else
{
if(tata_suprem(x)==tata_suprem(y))
fout<<"DA\n";
else
fout<<"NU\n";
}
}
return 0;
}