题意:
。。。
思路:
interesting graph去掉中心点和与其相连的边之后,成为一个所有点出度和入度都是1的图。
那么,可以用二分图的左半表示出度,右半表示入度。
则这个二分图的最大匹配是max_match。
与中心点相连的边有cnti条,other = m - cnti
则在我们构造的二分图中
需要删去的边:other - max_match
需要添加的边: n - max_match
int n, m, cx[Maxn+5], cy[Maxn+5], vis[Maxn+5], g[Maxn+5][Maxn+5], other;
int dfs(int x, int u) {
rep(i, 1, n) if (i != x && !vis[i] && g[u][i]) {
vis[i] = 1;
if (cy[i] == -1 || dfs(x, cy[i])) {
cx[u] = i; cy[i] = u; return 1;
}
}
return 0;
}
void pre(int ce) { // 贪心优化
rep(i, 1, n) if (i != ce && cx[i] == -1)
rep(j, 1, n) if (j != ce && cy[j] == -1 && g[i][j]) {
cx[i] = j; cy[j] = i; break;
}
}
int go (int ce) {
int cnt = 0, now = 0;
rep(i, 1, n) if (ce != i) {
if (!g[i][ce]) ++ cnt; else ++ now;
if (!g[ce][i]) ++ cnt; else ++ now;
}
other = m - now; if (!g[ce][ce]) ++ cnt; else -- other;
memset(cx, -1, sizeof(cx));
memset(cy, -1, sizeof(cy));
pre(ce);
rep(i, 1, n) if (i != ce && cx[i] == -1) {
memset(vis, 0, sizeof(vis));
dfs(ce, i);
}
int max_match = 0;
rep(i, 1, n) if (cx[i] != -1) ++ max_match;
return cnt + other - max_match + n - 1 - max_match;
}
int solve() {
int ans = inf;
rep(i, 1, n) {
ans = min (ans, go(i));
}
return ans;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
#endif
cin >> n >> m;
rep(i, 1, m) {
int x, y; cin >> x >> y;
g[x][y] = 1;
}
cout << solve();
return 0;
}