Pagini recente » Cod sursa (job #1353593) | Cod sursa (job #3321260) | Cod sursa (job #3342643) | Cod sursa (job #1001403) | Cod sursa (job #3322725)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n,m,tt[100001];
void op1(int x,int y)
{
int q=x;
while(q!=tt[q])
{
q=tt[q];
}
int p=y;
while(p!=tt[p])
{
p=tt[p];
}
tt[p]=q;
}
void op2(int x,int y)
{
int q=x;
while(q!=tt[q])
{
q=tt[q];
}
int p=y;
while(p!=tt[p])
{
p=tt[p];
}
if(p==q)
fout<<"DA"<<endl;
else
fout<<"NU"<<endl;
}
int main()
{
fin>>n>>m;
for(int i=1;i<=n;i++)
{
tt[i]=i;
}
for(int i=1;i<=m;i++)
{
int x,y,z;
fin>>x>>y>>z;
if(x==1)
{
op1(y,z);
}
else
{
op2(y,z);
}
}
return 0;
}