Blog of RuSun

\begin {array}{c} \mathfrak {One Problem Is Difficult} \\\\ \mathfrak {Because You Don't Know} \\\\ \mathfrak {Why It Is Diffucult} \end {array}

P5058 [ZJOI2004]嗅探器

P5058 [ZJOI2004]嗅探器

无向图中,找到一点割开 $A, B$ 两点,那么该点一定是割点。以 $A$ 为起点 tarjan ,找到一个割点 $u$ 满足 $low _ v \ge dfn _ u$ ,并且要保证割的是 $B$ 点,那么还需要满足 $dfn _ u < dfn _ B, dfn _ v \le dfn _ B$ 。

查看代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <cstdio>
#include <vector>
#define pb push_back
using namespace std;
template <class Type>
void read (Type &x)
{
char c;
bool flag = false;
while ((c = getchar()) < '0' || c > '9')
c == '-' && (flag = true);
x = c - '0';
while ((c = getchar()) >= '0' && c <= '9')
x = (x << 1) + (x << 3) + c - '0';
flag && (x = ~x + 1);
}
template <class Type, class ...rest>
void read (Type &x, rest &...y) { read(x), read(y...); }
template <class Type>
void write (Type x)
{
x < 0 && (putchar('-'), x = ~x + 1);
x > 9 && (write(x / 10), 0);
putchar('0' + x % 10);
}
const int N = 2e5 + 10;
int n, A, B;
bool cut[N];
vector <int> g[N];
int stmp, dfn[N], low[N];
void tarjan (int u)
{
dfn[u] = low[u] = ++stmp;
for (int v : g[u])
if (!dfn[v])
{
tarjan(v);
low[u] = min(low[u], low[v]);
if (u ^ A && low[v] >= dfn[u] && dfn[v] <= dfn[B])
cut[u] = true;
}
else low[u] = min(low[u], dfn[v]);
}
int main ()
{
read(n);
for (int a, b; ; )
{
read(a, b);
if (!a || !b) break;
g[a].pb(b), g[b].pb(a);
}
read(A, B);
tarjan(A);
for (int i = 1; i <= n; ++i) if (cut[i])
return printf("%d", i), 0;
puts("No solution");
return 0;
}