#include <bits/stdc++.h>
using namespace std ;
const int N = 6000, M = 7 * 1e4;
int all, nxt[M], go[M], hd[N];
void add(int x, int y) {
go[++all] = y, nxt[all] = hd[x], hd[x] = all;
}
stack<int> st;
int in[N], ct;
int pool, dfn[N], low[N], b[N], n, m;
void tar(int x, int fa) {
dfn[x] = low[x] = ++pool;
st.push(x);
int i, y;
int flag = 0;
for (i = hd[x]; i; i = nxt[i]) {
y = go[i];
if (y == fa && flag == 0) {
flag = 1;
continue;
}
if (!dfn[y]) {
tar(y, x), low[x] = min(low[x], low[y]);
} else if (!b[y])
low[x] = min(low[x], dfn[y]);
}
if (dfn[x] == low[x]) {
ct++;
do {
y = st.top();
st.pop();
b[y] = ct;
} while (x != y);
}
}
int main() {
int i, j, x, y;
cin >> n >> m;
for (i = 1; i <= m; i++)
cin >> x >> y, add(x, y), add(y, x);
for (i = 1; i <= n; i++)
if (!dfn[i])
tar(i, 0);
for (i = 1; i <= n; i++)
for (j = hd[i]; j; j = nxt[j]) {
x = b[i], y = b[go[j]];
if (x != y)
in[x]++;
}
x = 0;
for (i = 1; i <= ct; i++) {
if (in[i] == 1)
x++;
}
cout << (1 + x) / 2;
}
一本通1520:【 例 1】分离的路径
最新推荐文章于 2025-02-23 22:57:55 发布