Pagini recente » Cod sursa (job #2365446) | Cod sursa (job #140258) | Cod sursa (job #959808) | Cod sursa (job #1482668) | Cod sursa (job #2375680)
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n,m,t[100003];
int caut(int x)
{
if(t[x]==x)
return x;
else
{
t[x]=caut(t[x]);
return t[x];
}
}
int main()
{
fin>>n>>m;
for(int i=1;i<=n;i++)
t[i]=i;
for(int i=1;i<=m;i++)
{
int cer,x,y;
fin>>cer>>x>>y;
if(cer==1)
{
x=caut(x);
y=caut(y);
t[x]=y;
}
else
{
if(caut(x)==caut(y))
fout<<"DA"<<'\n';
else
fout<<"NU"<<'\n';
}
}
}