Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<vector>
- using namespace std;
- vector<int> head(100050,0);
- int root(int a){
- if(head[a]==a) return a;
- return head[a]=root(head[a]);
- }
- void mer(int a,int b){
- head[root(b)]=root(a);
- }
- bool check(int a,int b){
- return root(a)==root(b);
- }
- int main()
- {
- int n,m;
- bool k=false;
- scanf("%d%d",&n,&m);
- for(int i=1;i<=n;i++) head[i]=i;
- int u,v;
- while(m--){
- scanf("%d%d",&u,&v);
- if(check(u,v)) k=true;
- mer(u,v);
- }
- if(k) printf("Yes");
- else printf("No");
- return 0;
- }
- root(a);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement