至少增加的边数 =( 缩点后树总度数为1的结点数 + 1 )/ 2

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn= 1e4 + 10;
vector<int> g[maxn];
int dfn[maxn], low[maxn], dg[maxn], id;
bool vis[maxn];
int n, m;
void tarjan(int u, int fa) {
dfn[u] = low[u] = ++id;
vis[u] = 1;
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i];
if (v == fa) continue;
if (!dfn[v]) {
tarjan(v, u);
low[u] = min(low[u], low[v]);
}
else if (vis[v]) {
low[u] = min(low[u], dfn[v]);
}
}
}
void find_ebc() {
memset(dfn, 0, sizeof(dfn));
memset(low, 0, sizeof(low));
memset(vis, 0, sizeof(vis));
id = 0;
for (int i = 1; i <= n; i++) if (!dfn[i]) tarjan(i, -1);
}
int main() {
while (~scanf("%d%d", &n, &m)) {
for (int i = 1; i <= n; i++) g[i].clear();
int u, v;
for (int i = 1; i <= m; i++) {
scanf("%d%d", &u, &v);
g[u].push_back(v);
g[v].push_back(u);
}
find_ebc();
memset(dg, 0, sizeof(dg));
for (int u = 1; u <= n; u++) {
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i];
if (low[u] != low[v]) {
dg[low[u]]++;
}
}
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (dg[i] == 1) {
cnt++;
}
}
printf("%d\n", (cnt+1)/2);
}
return 0;
}