Pagini recente » Borderou de evaluare (job #2837531) | Borderou de evaluare (job #2263287) | Cod sursa (job #2571356)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int i,j,x,y,aux,p,t[100010],m,n;
int dettata(int x)
{
if(t[x]==x)
{
return x;
}
else
{
return dettata(t[x]);
}
}
int main()
{
fin>>n>>m;
for(i=1;i<=n;i++)
{
t[i]=i;
}
for(i=1;i<=m;i++)
{
fin>>p>>x>>y;
if(p==1)
{
if(x>y)
{
t[x]=y;
}
else
{
t[y]=x;
}
}
else
{
if(dettata(x)==dettata(y))
{
fout<<"DA"<<'\n';
}
else
{
fout<<"NU"<<'\n';
}
}
}
return 0;
}