P5058求助
  • 板块学术版
  • 楼主pfrig729
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/12/1 20:46
  • 上次更新2023/12/1 22:48:02
查看原帖
P5058求助
730178
pfrig729楼主2023/12/1 20:46
#include<bits/stdc++.h>
using namespace std;
int n,s,t,cnt,ans=numeric_limits<int>::max(),root,son,prt[200005],mak[200005],mp[5725][5725],dfn[200005],low[200005];
void dfs(int x)
{
	low[x]=dfn[x]=++cnt;
	for(int i=1;i<=n;i++)
	{
		if(prt[x]!=i&&mp[x][i])
		{
			if(!dfn[i])
			{
				prt[i]=x;
				dfs(i);
				low[x]=min(low[x],low[i]);
			}
			else
			{
				low[x]=min(low[x],dfn[i]);
			}
		}
	}
}
void che(int x)
{
	if(x==s)
	{
		return;
	}
	if(low[x]>=dfn[prt[x]]&&prt[x]!=s&&prt[x]<ans)
	{
		ans=prt[x];
	}
	che(prt[x]);
}
int main()
{
	scanf("%d",&n);
	int x,y;
	while(~scanf("%d%d",&x,&y))
	{
		if(x+y==0)
		{
			break;
		}
		mp[x][y]=mp[y][x]=1;
	}
	scanf("%d%d",&s,&t);
	dfs(s);
	che(t);
	if(ans==numeric_limits<int>::max())
	{
		printf("No solution");
	}
	else
	{
		printf("%d",ans);
	}
	return 0;
}

SubtaskSubtask #11 一会MLE一会RE

2023/12/1 20:46
加载中...