You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
const int INF = 0x3f3f3f3f;
|
|
|
|
|
const int N = 200010, M = N << 1;
|
|
|
|
|
int n;
|
|
|
|
|
bool st[N];
|
|
|
|
|
// 链式前向星
|
|
|
|
|
int e[M], h[N], idx, w[M], ne[M];
|
|
|
|
|
void add(int a, int b, int c = 0) {
|
|
|
|
|
e[idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx++;
|
|
|
|
|
}
|
|
|
|
|
int ans = INF;
|
|
|
|
|
int root, ed;
|
|
|
|
|
|
|
|
|
|
// Tarjan算法求割点
|
|
|
|
|
int dfn[N], low[N], ts;
|
|
|
|
|
void tarjan(int u, int fa) {
|
|
|
|
|
low[u] = dfn[u] = ++ts;
|
|
|
|
|
|
|
|
|
|
for (int i = h[u]; ~i; i = ne[i]) {
|
|
|
|
|
int v = e[i];
|
|
|
|
|
if (v == fa) continue;
|
|
|
|
|
if (!dfn[v]) {
|
|
|
|
|
tarjan(v, u);
|
|
|
|
|
low[u] = min(low[u], low[v]);
|
|
|
|
|
// u是割点
|
|
|
|
|
if (u != root && low[v] >= dfn[u]) {
|
|
|
|
|
if (u == ed) continue; // 根据题意,u必须在root和ed之间
|
|
|
|
|
if (dfn[ed] >= dfn[v]) ans = min(ans, u);
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
low[u] = min(low[u], dfn[v]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
// 初始化链式前向星
|
|
|
|
|
memset(h, -1, sizeof h);
|
|
|
|
|
|
|
|
|
|
scanf("%d", &n);
|
|
|
|
|
int x, y;
|
|
|
|
|
while (scanf("%d %d", &x, &y), x || y)
|
|
|
|
|
if (x != y) add(x, y), add(y, x);
|
|
|
|
|
|
|
|
|
|
scanf("%d %d", &root, &ed);
|
|
|
|
|
tarjan(root, -1); // 从其中一个信息中心开始遍历
|
|
|
|
|
|
|
|
|
|
if (ans == INF)
|
|
|
|
|
printf("No solution");
|
|
|
|
|
else
|
|
|
|
|
printf("%d", ans);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|