Pagini recente » Cod sursa (job #1732449) | Cod sursa (job #2285677) | Cod sursa (job #218989) | Cod sursa (job #554387) | Cod sursa (job #2553635)
#include <bits/stdc++.h>
using namespace std;
int n, m, i, x, y, tx, ty, t[100005], cerinta;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
int parinte (int x)
{
while (t[x]>0)
x=t[x];
return x;
}
int main () {
fin>>n>>m;
for (i=1;i<=n;i++)
t[i]=-1;
for (i=1;i<=m;i++) {
fin>>cerinta>>x>>y;
tx=parinte(x);
ty=parinte(y);
if (cerinta==2) {
if (tx!=ty) {
fout<<"NU\n";
}
else {
fout<<"DA\n";
}
} else {
if (t[tx]<t[ty]) {
t[tx]+=t[ty];
t[ty]=tx;
} else {
t[ty]+=t[tx];
t[tx]=ty;
}
}
}
return 0;
}