RE求助
查看原帖
RE求助
885434
zhengyuhao_666楼主2024/8/19 10:49
#include<bits/stdc++.h>
#define int long long
using namespace std;
vector<int> g[10005];
int n,m,p;
bool vis[10005];
bool dfs(int x,int y){
	if(x==y) return 1;
	vis[x]=1;
	for(auto v:g[x]){
		 if(!vis[v]){
	   	    if(dfs(v,y)) return 1;
	   }
	}  
}
signed main(){
	cin>>n>>m>>p;
	while(m--){
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
    
    }  
    for(int i=1;i<=p;i++){
    	int x,y;
    	cin>>x>>y;
    	memset(vis,0,sizeof(vis));
    	if(dfs(x,y))cout<<"Yes\n";
    	else cout<<"No\n";
    }
    return 0;
}
2024/8/19 10:49
加载中...