#include<bits/stdc++.h>
using namespace std;
int father[100005];
int n;
void init(){
for(int i=1;i<=n;i++){
father[i]=i;
}
}
int getfather(int x){
if(father[x]==x){
return x;
}
father[x]=getfather(father[x]);
return father[x];
}
int fun(int x,int y){
father[getfather(x)]=getfather(y);
}
int main(){
int m,a,b;
cin>>n>>m;
init();
while(m--){
cin>>a>>b;
if(getfather(a)!=getfather(b)){
fun(a,b);
}
}
int x,y;
cin>>x>>y;
if(getfather(x)==getfather(y)){
cout<<"YES";
}else{
cout<<"NO";
}
return 0;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题12.2 (C语言代码)浏览:809 |
C二级辅导-同因查找 (C语言代码)浏览:663 |
【亲和数】 (C语言代码)浏览:495 |
简单的a+b (C语言代码)浏览:692 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:758 |
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)浏览:523 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:483 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:621 |
1014题解浏览:485 |
演讲大赛评分 (C语言代码)浏览:1634 |