hdu3118Arbiter (利用二分圖的定義,枚舉每種狀態),hdu3118arbiter枚舉

來源:互聯網
上載者:User

hdu3118Arbiter (利用二分圖的定義,枚舉每種狀態),hdu3118arbiter枚舉
ArbiterTime Limit: 1000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 773 Accepted Submission(s): 401


Problem DescriptionArbiter is a kind of starship in the StarCraft science-fiction series. The Arbiter-class starship is a Protoss warship specializing in providing psychic support. Arbiters were crewed exclusively by Judicators; unlike other warships that were manned predominantly by Templar. The Judicator used the Arbiter as a base to provide support using space-time manipulation.
Arbiters could weaken space-time, tearing rifts in the fabric of space-time, creating a vortex linking another location to the Arbiter’s location. This could be used to move personnel over long distances between stars.
In the meantime of widely used Arbiter to transfer, KMXS, the captain of one Arbiter, was warning that some person had got a serious mental disorder after the trip on his Arbiter. By using mice as model animals, he found the sake, it’s because of chirality!
Every person has chirality, either left-handed or right-handed. Actually all the persons must live with the food which has the same chirality. When one person took Arbiter from one star to another one, his chirality will be changed (from left-handed to right-handed or from right-handed to left-handed). If a person took a long trip and finally got back to his own star, however, his chirality might be changed to the opposite state other than his original, which would cause fatal mental disorder, or even death.
KMXS has the channels map among the starts and he need to prohibit minimum number of channels from traveling so that wherever a person starts his traveling from when he gets his original star he’ll be safe. KMXS turns to your help.

InputThe first line of input consists of an integer T, indicating the number of test cases.
The first line of each case consists of two integers N and M, indicating the number of stars and the number of channels. Each of the next M lines indicates one channel (u, v) which means there is a bidirectional channel between star u and star v (u is not equal to v).

OutputOutput one integer on a single line for each case, indicating the minimum number of channels KMXS must prohibit to avoid mental disorder.

Constraints
0 < T <= 10
0 <= N <= 15 0 <= M <= 300
0 <= u, v < N and there may be more than one channel between two stars.

Sample Input

13 30 11 22 0

Sample Output
1題意:一個人從通道一個星球到另一個星球他的左手變右手,右手變左手,如果存在回到原來的星球他的左右手不是原來的狀態的話,這是致命的,為了使這種情況不能發生,最少需要冊除多少條邊。 也就是可以理解成:刪去最少的邊,使圖中不存在奇圈。二分圖的定義:在無向圖G中,至少有兩個點且如果存在迴路,那麼迴路必須為偶迴路。這樣才是二分圖。所以根據定義可知:把n個點分成兩部分,每一部分內的點集任意兩點不相連。把相連的邊就冊除。這樣的分法有2^n種。 最後找出冊除邊數最少的就是所要求的。
#include<stdio.h>#include<queue>#include<string.h>#include<iostream>using namespace std;int map[20][20],n;int deletEdg(int k){    int ans=0;    for(int i=0;i<n;i++)    for(int j=i+1;j<n;j++)    {        if((k&(1<<i))==0&&(k&(1<<j))==0)ans+=map[i][j];//在同一部分的點它們相連的邊數全部冊除        else if((k&(1<<i))!=0&&(k&(1<<j))!=0)ans+=map[i][j];    }    return ans;}int main(){    int m,t,a,b;    scanf("%d",&t);    while(t--)    {        scanf("%d%d",&n,&m);        memset(map,0,sizeof(map));        while(m--)        {            scanf("%d%d",&a,&b);            map[a][b]++; map[b][a]++;//必須這樣才能對        }        int MIN=99999999;        if(n==0||m==0)printf("0\n");        else{            for(int k=1;k<(1<<n);k++)//把n個數分成兩部分有2^n種狀態,每種狀態為k,在該狀態和第i位同為0的為第一部分,同為1的為另一部分            {                int t=deletEdg(k);                if(t<MIN)MIN=t;            }            printf("%d\n",MIN);        }    }}





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.