Pagini recente » Cod sursa (job #1413862) | Cod sursa (job #1101694) | Cod sursa (job #1021371) | Cod sursa (job #2980657) | Cod sursa (job #2626706)
#include<fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int d[100001],t[100001];
int rep(int x)
{
if(t[x]==0)
return x;
t[x]=rep(t[x]);
return t[x];
}
int main()
{
int n,m;
fin>>n>>m;
for(int i=1;i<=m;i++)
{
int op,x,y;
fin>>op>>x>>y;
if(op==1)
{
x=rep(x);
y=rep(y);
if(d[x]<d[y])
{
t[x]=y;
d[x]++;
}
else if(d[y]>d[x])
{
t[y]=x;
d[y]++;
}
else
{
t[x]=y;
d[x]++;
d[y]++;
}
}
else
{
x=rep(x);
y=rep(y);
if(x==y)
fout<<"DA\n";
else fout<<"NU\n";
}
}
}