Pagini recente » Cod sursa (job #1485435) | Cod sursa (job #1493700) | Cod sursa (job #3264455) | Cod sursa (job #2690651) | Cod sursa (job #3162347)
#include <fstream>
using namespace std;
ifstream cin ("disjoint.in");
ofstream cout ("disjoint.out");
int tata[100001];
int sef (int x)
{
if (tata[x]==x)
return x;
else
return tata[x]=sef (tata[x]);
}
void unire (int x, int y)
{
tata[sef(x)]=sef(y);
}
int main()
{
int n, m, op, x, y;
cin>>n>>m;
for (int i=1; i<=n; i++)
tata[i]=i;
for (int i=1; i<=m; i++)
{
cin>>op>>x>>y;
if (op==1)
unire (x, y);
else
{
if (sef(x)==sef(y))
cout<<"DA"<<'\n';
else
cout<<"NU"<<'\n';
}
}
return 0;
}