Pagini recente » Cod sursa (job #74733) | Cod sursa (job #25653) | Cod sursa (job #595409) | Cod sursa (job #1662105) | Cod sursa (job #3002613)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
///PRACTICE
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
const int NMAX=1e5+5;
int t[NMAX];
int p[NMAX];
int root(int x)
{
if(x==t[x])
return x;
return t[x]=root(t[x]);
}
void solve(int x,int y)
{
x=root(x);
y=root(y);
if(p[x]>p[y])
swap(x,y);
t[y]=x;
p[x]=p[x]+p[y];
}
void edge(int x,int y)
{
if(root(x)!=root(y))
solve(x,y);
}
int main()
{
int n,m,i,j,cer,x,y;
fin>>n>>m;
for(i=1;i<=n;i++)
{
t[i]=i;
p[i]=1;
}
for(i=1;i<=m;i++)
{
fin>>cer>>x>>y;
if(cer==1)
{
if(root(x)!=root(y))
solve(x,y);
}
else
{
if(root(x)!=root(y))
fout<<"NU\n";
else
fout<<"DA\n";
}
}
return 0;
}