题解:AT_abc427_c [ABC427C] Bipartize
注意到
code
#include <bits/stdc++.h>
using namespace std;
int n, m;
int ans; // 最少删几条边
pair < int, int > e[50];
bool col[15]; // 每个点染的颜色,因为只有 2 种颜色,所以我开了 bool
void dfs(int now) {
if (now > n) {
// 1~n 号点的颜色都考虑完了,计算此状况的最少删点数
int cnt = 0; // 记录答案
for (int i = 1; i <= m; i++)
if (col[e[i].first] == col[e[i].second]) cnt++;
ans = min(ans, cnt);
return ;
}
col[now] = true;
dfs(now + 1);
col[now] = false;
dfs(now + 1);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n>> m;
for (int i = 1; i <= m; i++) cin >> e[i].first>> e[i].second;
ans = m;
dfs(1);
cout << ans<< "\n";
return 0;
}
AC记录。