Pagini recente » Cod sursa (job #2156167) | Cod sursa (job #226382) | Cod sursa (job #1469462) | Cod sursa (job #2085432) | Cod sursa (job #1217450)
#include<fstream>
using namespace std;
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
const int nmax = 100010;
int p[nmax],n,m;
int find(int x)
{
return ((x==p[x])?x:(p[x]=find(p[x])));
}
int main()
{
cin>>n>>m;
for (int i=1;i<=n;i++) p[i]=i;
while (m--)
{
int type,a,b;
cin>>type>>a>>b;
if (type == 1)
p[find(a)]=find(b);
else
{
if (find(a)==find(b)) cout<<"DA\n";
else cout<<"NU\n";
}
}
return 0;
}