找割点,且去掉这个点后 S,T 两个点在2个块中
满足 U!=S && dfn[U] < dfn[T]
#include <bits/stdc++.h> using namespace std ; const int N=2e5+2; vector<int> g[N]; int n,m,low[N],dfn[N],ans=1e8,pool,S,T; void dfs(int x) { dfn[x]=low[x]=++pool; int y,i; for(i=0;i<g[x].size();i++){ y=g[x][i]; if(!dfn[y]){ dfs(y),low[x]=min(low[x],low[y]); if(x!=S&&low[y]>=dfn[x]&&dfn[y]<=dfn[T]){ ans=min(ans,x); } } else low[x]=min(low[x],dfn[y]); } } void add(int x,int y){ g[x].push_back(y); } int main(){ cin>>n; int x,y; while(cin>>x>>y,x&&y){ add(x,y);add(y,x); } cin>>S>>T; dfs(S); if(ans==1e8) cout<<"No solution";else cout<<ans; }
标签:int,ans,嗅探器,cin,dfn,&&,1523 From: https://www.cnblogs.com/towboa/p/16927971.html