洛谷P1551WA求助
作者:互联网
请问哪错了?萌新求助
#include <iostream>
using namespace std;
int n, m;
int p[60005];
int find(int x){
if (x!=p[x]) p[x]= find(p[x]);
return p[x];
}
int main(){
cin >> n >> m;
for (int i=1; i<=n; ++i) p[i] = i;
int a, b, f_a, f_b;
while (m--){
cin >> a >> b;
f_a = find(a);
f_b = find(b);
if(f_a!=f_b) p[f_a] = f_b;
}
int q;
cin >> q;
while (q--){
cin >> a >> b;
f_a = find(a);
f_b = find(b);
if (f_a==f_b) cout << "Yes";
else cout << "No";
}
return 0;
}
标签:std,洛谷,P1551WA,int,cin,求助,main,find 来源: https://blog.csdn.net/zxl2007123/article/details/121595956