Pagini recente » Borderou de evaluare (job #1274657) | Borderou de evaluare (job #1793914) | Borderou de evaluare (job #2339245) | Borderou de evaluare (job #2329188) | 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;
}