Pagini recente » Cod sursa (job #1124622) | Cod sursa (job #1069186) | Cod sursa (job #1259411) | Cod sursa (job #2938575) | Cod sursa (job #1968978)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int tata[100010];
int find_dad(int x)
{
if(x!=tata[x]) tata[x]=find_dad(tata[x]);
return tata[x];
}
int main()
{
int n,m,i,op,x,y;
fin>>n>>m;
for(i=1;i<=n;i++) tata[i]=i;
for(i=1;i<=m;i++)
{
fin>>op>>x>>y;
if(op==1)
{
tata[find_dad(x)]=tata[find_dad(y)];
}
else
{
if(find_dad(x)==find_dad(y)) fout<<"DA\n";
else fout<<"NU\n";
}
}
}