Pagini recente » Istoria paginii runda/simulare_oji2012_clasa_a_10-a/clasament | Cod sursa (job #1750369) | Cod sursa (job #2486776) | Cod sursa (job #1553884) | Cod sursa (job #1249097)
#include <fstream>
using namespace std;
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
int Root[100013];
int n,i,j,m,a,b,op;
int Find_root(int nod)
{
if (Root[nod]==nod) return nod;
else return Find_root(Root[nod]);
}
void unite ( int a, int b)
{
if (a!=b) Root[b]=a;
}
int main()
{
cin>>n>>m;
for (i=1;i<=n;++i) Root[i]=i;
while(m--)
{
cin>>op>>a>>b;
int r1=Find_root(a);
int r2=Find_root(b);
if (op==1) unite(r1,r2);
if (op==2){
if (r1==r2) cout<<"DA\n";
else cout<<"NU\n";
}
}
return 0;
}