Pagini recente » Cod sursa (job #1981597) | Cod sursa (job #1584234) | Cod sursa (job #2169684) | Cod sursa (job #1080949) | Cod sursa (job #1917374)
#include <bits/stdc++.h>
using namespace std;
int n,m,v[100003];
int Find(int x)
{
while(v[x]!=0)
x=v[x];
return x;
}
void Union(int x, int y)
{
v[x]=y;
}
int main()
{
int i,op,x,y;
ifstream fin("disjoint.in");
fin>>n>>m;
ofstream fout("disjoint.out");
for(i=1;i<=m;i++)
{
fin>>op>>x>>y;
if(op==1) Union(x,y);
else
if(Find(x)==Find(y)) fout<<"DA\n";
else fout<<"NU\n";
}
fin.close();
fout.close();
return 0;
}