Pagini recente » Cod sursa (job #2614316) | Cod sursa (job #2673120) | Cod sursa (job #246451) | Cod sursa (job #728558) | Cod sursa (job #2525583)
#include <fstream>
using namespace std;
int n, m, i, x, y, z, tx, ty;
int tata[100001];
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
int parinte (int x)
{
while (tata[x]>0)
x=tata[x];
return x;
}
int main () {
fin>>n>>m;
for (i=1;i<=n;i++)
tata[i]=-1;
for (i=1;i<=m;i++) {
fin>>z>>x>>y;
tx=parinte(x);
ty=parinte(y);
if (z==2) {
if (tx!=ty)
fout<<"NU\n";
else
fout<<"DA\n";
} else if (z==1){
if (tx<ty) {
tata[tx]+=tata[ty];
tata[ty]=tx;
} else {
tata[ty]+=tata[tx];
tata[tx]=ty;
}
}
}
return 0;
}