Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream in ("disjoint.in");
- ofstream out ("disjoint.out");
- int i,v[100];
- int n,m,c,x,y;
- int caut (int i){
- if (v[i]!=i) v[i]=caut(v[i]);
- return v[i];}
- void unire (int x,int y) v[caut(x)]=caut(y);
- int main()
- {in>>n>>m;
- for (i=0;i<n;i++) v[i]=i;
- for (i=0;i<n;i++) {
- in>>c>>x>>y;
- if (c==1) unire (x,y);
- if ((c==2)&&(caut(x)==caut(y))) out<<"Da"<<endl;
- else out<<"Nu"<<endl;}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement