HDU 3118 Arbiter 判定奇圈

來源:互聯網
上載者:User

標籤:class   blog   code   http   tar   color   

題目來源:HDU 3118 Arbiter

題意:翻譯過來就是不能有奇圈 每走一步狀態會變化 當他回到起點時如果和原來的狀態不一樣 可能會死 求至少去掉多少條邊可以避免這種狀況發生

思路:二分圖是沒有奇圈的 最多就15個點 我們用狀態壓縮枚舉那些點是在二分圖的一邊和另外一邊 確定二分圖之後枚舉輸入的邊 每條邊串連的不能是同一集合的點

不符合就去掉 最後取小

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


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.