Source: HDU 3118 arbiter
The odd circle does not change every step. When he returns to the starting point, if it is different from the original state, he may die to find at least how many sides can be removed to avoid this situation.
Ideas: in a bipartite graph, there is no Odd Circle. for a maximum of 15 vertices, we compress the state to enumerate those vertices. The vertices are connected to each side of the Bipartite Graph and the other side after determining the bipartite graph. cannot be the point of the same set.
Remove the last small value if it does not match
#include <cstdio>#include <cstring>#include <cstdlib>#include <vector>#include <algorithm>using namespace std;const int maxn = 510;struct node{int t1, t2, x1, y1, x2, y2;}a[maxn];int vis[maxn];int y[maxn];vector <int> G[maxn];int n;int color[maxn];int sum = 0;bool dfs(int u){for(int i = 0; i < G[u].size(); i++){int v = G[u][i];if(vis[v])continue;vis[v] = true;if(y[v] == -1 || dfs(y[v])){y[v] = u;return true;}}return false;}int match(){int ans = 0;memset(y, -1, sizeof(y));for(int i = 0; i < n; i++){memset(vis, 0, sizeof(vis));if(dfs(i))ans++;}return ans;}int main(){int T;scanf("%d", &T);while(T--){int m;scanf("%d %d", &n, &m);for(int i = 0; i < n; i++)G[i].clear();while(m--){int u, v;scanf("%d %d", &u, &v);G[u].push_back(v);//G[v].push_back(u);}int ans = 999999999;for(int s = 0; s < (1<<n); s++){memset(color, 0, sizeof(color));for(int i = 0; i < n; i++)if(s&(1<<i))color[i] = 1;sum = 0;for(int i = 0; i < n; i++)for(int j = 0; j < G[i].size(); j++)if(color[i] == color[G[i][j]])sum++;ans = min(ans, sum);}printf("%d\n", ans);}return 0;}