NC50403 嗅探器
作者:互联网
题目链接
https://ac.nowcoder.com/acm/problem/50403
题意
求 \(a\) 到 \(b\) 路径上编号最小的割点。
思路
以\(a\)为根节点建树,则当前割点\(v\)是否在路径上其时间戳到达时间必须比\(b\)晚,也就是\(dfn[b] >= dfn[v]\).
AC代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 50;
const int INF = 0x3f3f3f3f;
struct node{
int to, next;
} edge[maxn];
int tot, cnt;
int dfn[maxn], low[maxn];
int head[maxn];
bool is_true[maxn];
void add(int from, int to){
edge[++cnt].to = to;edge[cnt].next = head[from];head[from] = cnt;
}
void ins(int u, int v){add(u, v); add(v, u);}
int st, ed, ans;
void Tarjan(int u){
dfn[u] = low[u] = ++tot;
for(int i = head[u];i ;i = edge[i].next){
int v = edge[i].to;
if(!dfn[v]){
Tarjan(v);
low[u] = min(low[u], low[v]);
if(low[v] >= dfn[u] && u != st && dfn[v] <= dfn[ed]){
ans = min(ans, u);
}
}
low[u] = min(low[u], dfn[v]);
}
}
int main()
{
std::ios::sync_with_stdio(false);
int n, u, v;
cin >> n;
while(cin >> u >> v){
if(!u&& !v) break;
add(u, v), add(v, u);
}
cin >> st >> ed;
ans = INF;
Tarjan(st);
if(ans == INF) cout << "No solution" << endl;
else cout << ans << endl;
return 0;
}
标签:int,嗅探器,NC50403,edge,add,dfn,maxn,low 来源: https://www.cnblogs.com/Carered/p/14275299.html