Pagini recente » Cod sursa (job #436091) | Cod sursa (job #554299) | Rating BladeK23 (GvBK) | Cod sursa (job #2099040) | Cod sursa (job #1290636)
# include <bits/stdc++.h>
using namespace std;
const int nmax = 1e5 + 5;
int s[nmax],v[nmax];
int poz(int x)
{
while (s[x] != x) x=s[x];
return x;
}
void comb(int x,int y)
{
if (v[x] == v[y])
{
++v[x];s[x]=y;
}
if (v[x] < v[y]) swap(x,y);
s[x]=y;
}
int main(void)
{
int n,m,t,x,y;
ifstream fi("disjoint.in");
ofstream fo("disjoint.out");
fi>>n>>m;
for (int i=1;i<=n;++i) s[i]=i;
while (m --)
{
fi>>t>>x>>y;
if (t == 1) comb(poz(x),poz(y));else fo << (poz(x) == poz(y) ? "DA\n":"NU\n");
}
return 0;
}