Pagini recente » Cod sursa (job #1050301) | Cod sursa (job #2425216) | Cod sursa (job #267963) | Cod sursa (job #511876) | Cod sursa (job #2488786)
#include <fstream>
#include <algorithm>
using namespace std;
long long t[100010];
long long i,n,m,tip,rx,ry,x,y;
long long Radacina_lui (long long x) {
while (t[x]>0) {
x=t[x];
}
return x;
}
int main() {
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
fin>>n>>m;
for (i=1;i<=n;i++) {
t[i]=-1;
}
for (i=1;i<=m;i++) {
fin>>tip>>x>>y;
rx=Radacina_lui(x);
ry=Radacina_lui(y);
if (tip==1) {
if (rx!=ry) {
if (t[rx]<t[ry]) {
t[rx]+=t[rx];
t[ry]=rx;
}
else {
t[ry]+=t[rx];
t[rx]=ry;
}
}
}
else {
if (rx==ry) fout<<"DA"<<"\n";
else fout<<"NU"<<"\n";
}
}
return 0;
}