求助 最后一个点RE
查看原帖
求助 最后一个点RE
494992
underline__jian楼主2022/3/5 22:44
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=2e5+15;
struct node{
	int head,v,nxt;
}e[N];
bool vis[N];
int tot;
inline void add(int x,int y){
	e[++tot].v=y;
	e[tot].nxt=e[x].head;
	e[x].head=tot;
}
inline void dfs(int x,int loc,int fa){
	vis[x]=true;
	for(int i=e[x].head;i;i=e[i].nxt){
		if(e[i].v==fa||e[i].v==loc||vis[e[i].v]) continue;
		dfs(e[i].v,loc,x);
	}
}
inline int read(){
	int x=0,y=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') y=-y;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*y;
}
int main(){
	int n=read();
	while(1){
		int x=read(),y=read();
		if(x==0&&y==0) break;
		add(x,y); add(y,x);
	}
	int a=read(),b=read();
	for(int i=1;i<=n;i++){
		memset(vis,0,sizeof(vis));
		if(i==a||i==b) continue;
		dfs(a,i,0);
		if(!vis[b]){
			printf("%d",i);
			return 0;
		}
	}
	puts("No solution");
	return 0;
}
2022/3/5 22:44
加载中...