Pagini recente » Cod sursa (job #2423732) | Cod sursa (job #73893) | Cod sursa (job #118170) | Cod sursa (job #2381009) | Cod sursa (job #916920)
Cod sursa(job #916920)
#include<fstream>
#include <stddef.h>
#define maxn 100001
using namespace std;
int N,M;
struct multime{
multime *tata;
}V[maxn];
ifstream f("disjoint.in");
ofstream g("disjoint.out");
void connectM(int x,int y){
multime *t=&V[x],*f=&V[y];
while(t->tata) //tata
t=t->tata;
while(f->tata) //fiu
f=f->tata;
f->tata=t;
}
void afis(int x){
if(x)g<<"DA\n";
else g<<"NU\n";
}
void test(int x,int y){
multime *t=&V[x],*f=&V[y];
while(t->tata)
t=t->tata;
while(f->tata)
f=f->tata;
if(t==f)
afis(1);
else
afis(0);
}
int main(){
int c,x,y;
f>>N>>M;
for(int i=0;i<M;i++){
f>>c>>x>>y;
if(c==1)
connectM(x,y);
else
test(x,y);
}
return 0;
}