Pagini recente » Monitorul de evaluare | Monitorul de evaluare | Diferente pentru utilizator/coldfire intre reviziile 3 si 2 | Cod sursa (job #3360312) | Cod sursa (job #3360292)
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int parent[100001];
int root(int x)
{
if(parent[x]==x)
{
return x;
}
return parent[x]=root(parent[x]);
}
void uniune(int x,int y)
{
int r1=root(x);
int r2=root(y);
if(r1!=r2)
{
parent[r1]=r2;
}
}
int main()
{
int n,i,j,m,x,y,tip;
fin>>n>>m;
for(i=1;i<=n;i++)
{
parent[i]=i;
}
for(i=1;i<=m;i++)
{
fin>>tip>>x>>y;
if(tip==1)
{
uniune(x,y);
}
else
{
if(root(x)==root(y))
{
fout<<"DA"<<"\n";
}
else fout<<"NU"<<"\n";
}
}
return 0;
}