Pagini recente » Cod sursa (job #2317853) | Cod sursa (job #1013849) | Cod sursa (job #1660552) | Cod sursa (job #1118779) | Cod sursa (job #3222925)
#include <bits/stdc++.h>
#define N 100009
using namespace std;
ifstream fin("disjoint.in");ofstream fout("disjoint.out");
int n,q;
int tata[N];
int Find(int x)
{
if( !tata[x] )return x;
int father=Find( tata[x] );
tata[x]=father;
return tata[x];
}
void Union(int x,int y)
{
int tx,ty;
tx=Find(x);
ty=Find(y);
if( tx==ty )
return ;
if( tx<ty )
tata[ tx ]=ty;
else
tata[ ty ]=tx;
}
void T1()
{
int x,y;
fin >> x >> y;
Union(x,y);
}
void T2()
{
int x,y;
fin >> x >> y;
if( Find(x)==Find(y) )fout << "DA\n";
else fout << "NU\n";
}
int main()
{
fin >> n>> q;
while(q--)
{
int c;
fin >> c;
if( c==1 )
T1();
else
T2();
}
fin.close();fout.close();
return 0;
}