题解 P5058 【[ZJOI2004]嗅探器】
(
考虑缩点时的过程,设
由此我们这样想:如果我们以一个信息中心
这很显然,由于
那么如果把
算法只对原
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <queue>
const int maxn(200010);
const int maxm = 500010;
using namespace std;
int top = 1, head[maxn], n, a, b;
struct node {
int to, nxt;
} edge[maxm<<1];
void tarjan(int);
bool cut[maxn];
inline void insert(int u, int v) {
edge[++top] = (node) {v, head[u]};
head[u] = top;
}
int main() {
scanf("%d", &n);
int u, v;
scanf("%d %d", &u, &v);
while (!(u==0 && v==0)) {
insert(u, v), insert(v, u);
scanf("%d %d", &u, &v);
}
scanf("%d %d", &a, &b);
tarjan(a);
for(int i = 1; i <= n; i++)
if(cut[i]) {
printf("%d", i);
return 0;
}
puts("No solution");
return 0;
}
int dfn[maxn], low[maxn], timer;
void tarjan(int u) {
dfn[u] = low[u] = ++timer;
for(int i = head[u]; i; i = edge[i].nxt) {
int v = edge[i].to;
if(!dfn[v]) {
tarjan(v);
low[u] = min(low[u], low[v]);
if(low[v]>=dfn[u] && u!=a && dfn[b]>=dfn[v])
cut[u] = 1;
} else
low[u] = min(low[u], dfn[v]);
}
return;
}