Pagini recente » Cod sursa (job #2888548) | Cod sursa (job #212664) | Cod sursa (job #3138919) | Cod sursa (job #1742991) | Cod sursa (job #1235848)
#include <fstream>
using namespace std;
const int NMax = 100005;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int N, M,T[NMax];
int Root(int x)
{
while(x!=T[x])
x=T[x];
return x;
}
void Unite(int x,int y)
{
T[x]=y;
}
int main()
{
fin>>N>>M;
for(int i=1;i<=N;i++)
T[i]=i;
while(M--)
{
int op,x,y;
fin>>op>>x>>y;
if(op==1)
{
Unite(Root(x),Root(y));
}
if(op==2)
{
if(Root(x)==Root(y))
fout<<"DA\n";
else
fout<<"NU\n";
}
}
return 0;
}