HDU 3118 arbiter determines odd circles

Source: Internet
Author: User

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;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.