Pagini recente » Cod sursa (job #559746) | Cod sursa (job #2970897) | Cod sursa (job #2747643) | Cod sursa (job #3154725) | Cod sursa (job #2759518)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n,m;
int t[100005];
inline void Union(int x, int y)
{
t[y]=x;
}
inline int Find(int x)
{
int rad, y;
rad=x;
while(t[rad])
rad=t[rad];
while(t[x])
{
y=t[x];
t[x]=rad;
x=y;
}
return rad;
}
inline void Rezolvare()
{
fin>>n>>m;
for(int i=1; i<=m; i++)
{
int cod, x, y;
fin>>cod>>x>>y;
x=Find(x);
y=Find(y);
if(cod==1)
Union(x,y);
else
{
if(x==y) fout<<"DA\n";
else fout<<"NU\n";
}
}
}
int main()
{
Rezolvare();
return 0;
}