Pagini recente » Cod sursa (job #1062337) | Cod sursa (job #2402919) | Cod sursa (job #1408237) | Cod sursa (job #324156) | Cod sursa (job #3272097)
#include <bits/stdc++.h>
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int t[100005],n,m,o,x,y;
void op1(int x, int y)
{
int ai=t[x],aj=t[y];
for(int j=1;j<=n;j++)
if(t[j]==ai)
t[j]=aj;
}
void op2(int x, int y)
{
if(t[x]==t[y])
out<<"DA"<<'\n';
else
out<<"NU"<<'\n';
}
int main()
{
in>>n>>m;
for(int i=1;i<=n;i++)
t[i]=i;
for(int i=1;i<=m;i++){
in>>o>>x>>y;
if(o==1)
op1(x,y);
else
op2(x,y);
}
return 0;
}