rt,交上去 WA #5 #6,其中有一个甚至显示了 "Too short on line 1."
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, M = 20;
int n, a, b, dfn[N], low[N], ts, stk[N], top, squ;
vector<int> tmp[N], v[N << 1];
void tarjan(int x, int fa) {
dfn[x] = low[x] = ++ ts;
stk[++ top] = x;
for(int i : tmp[x]) {
if(i == fa) {
continue;
}
if(!dfn[i]) {
tarjan(i, x);
low[x] = min(low[x], low[i]);
if(low[i] >= dfn[x]) {
squ ++;
while(top && stk[top] != x) {
v[squ].push_back(stk[top]), v[stk[top]].push_back(squ);
top --;
}
v[squ].push_back(x), v[x].push_back(squ);
}
} else {
low[x] = min(low[x], dfn[i]);
}
}
}
void dfs(int x, int ans, int fa) {
if(x == b) {
if(ans < 0x3f3f3f3f / 2) {
cout << ans << endl, exit(0);
}
return;
}
if(x <= n && v[x].size() > 1 && x != a) {
ans = min(ans, x);
}
for(int i : v[x]) {
if(i == fa) {
continue;
}
dfs(i, ans, x);
}
}
signed main() {
cin >> n, squ = n;
for(int x, y; ; ) {
cin >> x >> y;
if(!x && !y) {
break;
}
tmp[x].push_back(y), tmp[y].push_back(x);
}
cin >> a >> b;
tarjan(a, 0);
dfs(a, 0x3f3f3f3f, 0);
return cout << "No solution" << endl, 0;
}