Description
给出一个无向图, 要求找出某个点$u$, 去掉$u$和$u$所连的边, 所剩下的节点构成一棵树。
Solution
首先, 割点肯定是不可能满足条件的, 因为去掉割点后会构成若干个不连通的图。
所以我们先求出割点, 再查找不是割点, 并且 去掉它连接的边, 剩下的 边数为$N-2$, 只有这种点才能够满足要求。
Code
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define rd read()
using namespace std; const int N = 1e5 + ; int head[N], tot;
int low[N], dfn[N], cnt, cut[N], d[N];
int n, m; vector<int> q; struct edge {
int nxt, to;
}e[N << ]; int read() {
int X = , p = ; char c = getchar();
for (; c > '' || c < ''; c = getchar()) if (c == '-') p = -;
for (; c >= '' && c <= ''; c = getchar()) X = X * + c - '';
return X * p;
} void add(int u, int v) {
e[++tot].to = v;
e[tot].nxt = head[u];
head[u] = tot;
} void tarjan(int u) {
low[u] = dfn[u] = ++cnt;
int flag = ;
for (int i = head[u]; i; i = e[i].nxt) {
int nt = e[i].to;
if (!dfn[nt]) {
tarjan(nt);
low[u] = min(low[u], low[nt]);
if (low[nt] >= dfn[u]) {
flag ++;
if (flag > || u - )
cut[u] = ;
}
}
else low[u] = min(low[u], dfn[nt]);
}
} int main()
{
n = rd; m = rd;
for (int i = ; i <= m; ++i) {
int u = rd, v = rd;
add(u, v); add(v, u);
d[u]++; d[v]++;
}
tarjan();
for (int i = ; i <= n; ++i)
if (!cut[i] && m - d[i] == n - )
q.push_back(i);
printf("%d\n", (int)q.size());
for (int i = , len = q.size(); i < len; ++i)
printf("%d ", q[i]);
puts("");
}