Pagini recente » Cod sursa (job #706864) | Cod sursa (job #1451284) | Cod sursa (job #1772415) | Cod sursa (job #534972) | Cod sursa (job #3185879)
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD 1000000007
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int parent[100001];
int height[100001];
int root(int x)
{
if(parent[x]==x)
{
return x;
}
else
{
return parent[x]=root(parent[x]);
}
}
int unite(int a,int b)
{
a=root(a),b=root(b);
if(height[a] < height[b])
{
swap(a,b);
}
parent[b]=a;
height[a]+=height[b];
}
int main()
{
int n,m;
fin >> n >> m;
for(int i=1;i<=n;i++)
{
parent[i]=i,height[i]=1;
}
while(m--)
{
int t,x,y;
fin >> t >> x >> y;
if(t==1)
{
unite(x,y);
}
else
{
fout << (root(x)==root(y) ? "DA" : "NU");
fout << "\n";
}
}
}