Pagini recente » Cod sursa (job #2602707) | Cod sursa (job #3184301) | Cod sursa (job #318191) | Cod sursa (job #269453) | Cod sursa (job #3272093)
#include <bits/stdc++.h>
using namespace std;
ifstream in ("disjoint.in");
ofstream out ("disjoint.out");
int t[100008],n,m,o,x,y;
void op1(int x,int y)
{
int ai=t[y], aj=t[x];
for(int i=1;i<=n;i++)
if(t[i]==ai)
t[i]=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);
if(o==2)
op2(x,y);
}
return 0;
}