Pagini recente » Cod sursa (job #1947653) | Cod sursa (job #3206732) | Cod sursa (job #2691163) | Cod sursa (job #1016660) | Cod sursa (job #2448317)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n,m,x,y,tip;
int v[1000001];
vector<int>multimi[1000001];
int main()
{
fin>>n>>m;
for(int i=1;i<=n;i++)
{
v[i]=i;
multimi[i].push_back(i);
}
for(int i=1;i<=m;i++)
{
fin>>tip>>x>>y;
if(tip==1)
{
if(multimi[v[x]].size()>multimi[v[y]].size())
swap(x,y);
int val=multimi[v[x]].size();
int aux=v[x];
for(int j=0;j<val;j++)
{
multimi[v[y]].push_back(multimi[aux][j]);
v[multimi[aux][j]]=v[y];
}
multimi[aux].clear();
}
if(tip==2)
{
if(v[x]==v[y])
fout<<"DA";
else
fout<<"NU";
fout<<'\n';
}
}
return 0;
}