# xmu 1100无向图最小割

#include <iostream>
using namespace std;
int mat[110][110];
int res;

void Mincut(int n) {
int node[110], dist[110];
bool visit[110];
int i, prev, maxj, j, k;
for (i = 0; i < n; i++)
node[i] = i;
while (n > 1) {
int maxj = 1;
for (i = 1; i < n; i++) { //初始化到已圈集合的割大小
dist[node[i]] = mat[node[0]][node[i]];
if (dist[node[i]] > dist[node[maxj]])
maxj = i;
}
prev = 0;
memset(visit, false, sizeof (visit));
visit[node[0]] = true;
for (i = 1; i < n; i++) {
if (i == n - 1) { //只剩最后一个没加入集合的点，更新最小割
res = min(res, dist[node[maxj]]);
for (k = 0; k < n; k++) //合并最后一个点以及推出它的集合中的点
mat[node[k]][node[prev]] = (mat[node[prev]][node[k]] += mat[node[k]][node[maxj]]);
node[maxj] = node[--n]; //缩点后的图
}
visit[node[maxj]] = true;
prev = maxj;
maxj = -1;
for (j = 1; j < n; j++)
if (!visit[node[j]]) { //将上次求的maxj加入集合，合并与它相邻的边到割集
dist[node[j]] += mat[node[prev]][node[j]];
if (maxj == -1 || dist[node[maxj]] < dist[node[j]])
maxj = j;
}
}

}
return;
}

int main() {
int n, m, a, b;
while (scanf("%d%d", &n, &m) != EOF) {
res = (1 << 29);
memset(mat, 0, sizeof (mat));
while (m--) {
scanf("%d%d", &a, &b);
mat[a][b] += 1;
mat[b][a] += 1;
}
Mincut(n);
printf("%d\n", res);
}
}

07-29 1382

03-27 3149

01-09 1473

02-10 4224

10-07 4596

07-17 1468

03-13 1411

11-22 1298

05-29 1377

10-29 482