Pagini recente » Cod sursa (job #2609362) | Cod sursa (job #1300999) | Cod sursa (job #212270) | Cod sursa (job #870608) | Cod sursa (job #2041992)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int get_root(int node,vector<int> &nodeFather)
{
if(nodeFather[node]==node)
return node;
else
{
nodeFather[node]=get_root(nodeFather[node],nodeFather);
return nodeFather[node];
}
}
int main()
{
int n,o,type,x,y;
fin>>n>>o;
vector<int> nodeFather(n+5);
for(int i=1;i<=n;i++)
{
nodeFather[i]=i;
}
for(;o;o--)
{
fin>>type>>x>>y;
x=get_root(x,nodeFather);
y=get_root(y,nodeFather);
if(type==1)
{
nodeFather[y]=x;
}
else
{
if(x==y)
{
fout<<"DA\n";
}
else
{
fout<<"NU\n";
}
}
}
return 0;
}