Pagini recente » Cod sursa (job #1363121) | Cod sursa (job #2236967) | Cod sursa (job #293554) | Cod sursa (job #160647) | Cod sursa (job #1307138)
#include <bits/stdc++.h>
using namespace std;
int n,i,j,m,op,a,b;
int Root[100013];
inline int find_root(int nod)
{
if (Root[nod]==nod) return nod;
return Root[nod]=find_root(Root[nod]);
}
inline void unite(int a,int b)
{
if (a!=b) Root[b]=a;
}
inline void initialize_root(int limit)
{
for (int i=1;i<=limit;++i) Root[i]=i;
}
int main(void)
{
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
cin>>n>>m;
initialize_root(n);
while(m--)
{
cin>>op>>a>>b;
a=find_root(a);
b=find_root(b);
if (op==1) unite(a,b);
if (op==2)
{
if(a==b) cout<<"DA\n";
else cout<<"NU\n";
}
}
return 0;
}