如果这个点是割点且删去后, 和 在不同的连通块就可行
现在问题关键就是如何判断这个割点是否把 , 隔开来了
那么现在我们从 点开始
想象一下 是 的儿子,如果 说明 是割点
删掉 后, 和 必定隔开来
那如果 在 的一侧,不就说明 和 隔开了吗?
那 在 的一侧不就说明 吗?
因为 是继 第一个被访问的,所以如果
说明b在u的那一侧,删掉这个点不一定可行
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
int n,l,r;
struct edge{ int to,nxt; } d[maxn];
int head[maxn],cnt=1;
void add(int u,int v){ d[++cnt]=(edge){v,head[u]},head[u]=cnt; }
int dfn[maxn],low[maxn],stac[maxn],id,top,cut[maxn];
void tarjan(int u,int root)
{
low[u]=dfn[u]=++id,stac[++top]=u;
int flag=0;
for(int i=head[u];i;i=d[i].nxt )
{
int v=d[i].to;
if( !dfn[v] )
{
tarjan(v,root);
low[u]=min( low[u],low[v] );
if( dfn[u]<=low[v] )
{
flag++;
if( u!=root||flag>=2 )
{
if( dfn[v]<=dfn[r] ) cut[u]=1;
}
}
}
else low[u]=min( low[u],dfn[v] );
}
}
int ans[maxn];
int main()
{
cin >> n;
while( cin >> l >> r && (l+r)!=0 ) add(l,r),add(r,l);
cin >> l >> r;
tarjan(l,l);
for(int i=1;i<=n;i++)
if( cut[i]&&i!=l&&i!=r )
{
cout << i;
return 0;
}
cout << "No solution";
}