P5058 [ZJOI2004] 嗅探器
题解
割点的特性:
以 s 为根节点dfs,割点的dfn序小于 t 点,且在割点dfs之后 t 点才有dfn序
code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<ll> G[200005];
ll dfn[200005],low[200005];
ll cnt=0;
ll ans[200005]={0};
ll s,t;
void scc(ll now,ll fa)
{
dfn[now]=++cnt;
low[now]=dfn[now];
for(auto next:G[now])
{
if(next==fa) continue;
if(!dfn[next])
{
scc(next,now);
if(now!=s&&low[next]>=dfn[now]&&dfn[t]>=dfn[next]) ans[now]=1;
low[now]=min(low[now],low[next]);
}
else low[now]=min(low[now],dfn[next]);
}
}
void solve()
{
ll n;
cin>>n;
ll x,y;
while(cin>>x>>y&&x!=0&&y!=0)
{
G[x].push_back(y);
G[y].push_back(x);
}
cin>>s>>t;
scc(s,s);
for(ll i=1;i<=n;i++)
{
if(ans[i])
{
cout<<i;
return ;
}
}
cout<<"No solution";
return;
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int TT=1;
while(TT--) solve();
return 0;
}

浙公网安备 33010602011771号