Pagini recente » Cod sursa (job #1887200) | Borderou de evaluare (job #2538125) | Profil tabara | Cod sursa (job #143719) | Cod sursa (job #1869357)
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int t[100001];
int root(int x)
{
if(t[x]==0)
return x;
t[x]=root(t[x]);
return t[x];
}
int main()
{
int n,m,i,op,x,y;
fin>>n>>m;
for(i=1;i<=m;i++)
{
fin>>op>>x>>y;
if(op==1)
{
t[root(x)]=root(y);
}
else
{
if(root(x)==root(y))
fout<<"DA"<<'\n';
else
fout<<"NU"<<'\n';
}
}
return 0;
}