比赛描述
Arbiter 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 righthanded 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.
输入
The 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).
0 < T <= 10
0 <= N <= 15 0 <= M <= 300
0 <= u, v < N and there may be more than one channel between two stars.
输出
Output one integer on a single line for each case, indicating the minimum number of channels
KMXS must prohibit to avoid mental disorder.
样例输入
1
3 3
0 1
1 2
2 0
样例输出
1
提示
undefined
题目来源
ACM ICPC Greater New York Region 2008
/* AC 171MS #include<iostream> #define N 16 int a[N][N]; int g0[N]; int g1[N]; int main(){ // freopen("test.txt","r",stdin); int t,n,m,i,j,k,delNum,minDelNum; scanf("%d",&t); while(t--){ minDelNum = INT_MAX; memset(a,0,sizeof(a)); scanf("%d%d",&n,&m); for(k=0;k<m;k++){ scanf("%d%d",&i,&j); a[i][j]++; a[j][i]++; } if(n==1 || m<=1){ printf("0\n"); continue; } int s = 1<<(n+1); //可优化:最高位就放在第一组 int c0,c1; for(k=0;k<s;k++){ c0 = c1 = 0; delNum = 0; for(i=0;i<n;i++){ if(k&(1<<i)){ g0[c0++] = i; }else{ g1[c1++] = i; } } for(i=0;i<c0;i++){ for(j=0;j<i;j++){ delNum += a[g0[i]][g0[j]]; } } for(i=0;i<c1;i++){ for(j=0;j<i;j++){ delNum += a[g1[i]][g1[j]]; } } if(delNum < minDelNum){ minDelNum = delNum; } } printf("%d\n",minDelNum); } } */ /* AC 78MS #include<iostream> #define N 15 int a[N][N]; int g0[N]; int g1[N]; int main(){ // freopen("test.txt","r",stdin); int t,n,m,i,j,k,delNum,minDelNum; scanf("%d",&t); while(t--){ minDelNum = INT_MAX; memset(a,0,sizeof(a)); scanf("%d%d",&n,&m); for(k=0;k<m;k++){ scanf("%d%d",&i,&j); a[i][j]++; a[j][i]++; } if(n==1 || m<=1){ printf("0\n"); continue; } int s = 1<<n; int c0,c1; for(k=0;k<s;k++){ c0 = c1 = 0; delNum = 0; g0[c0++] = n-1; for(i=0;i<n-1;i++){ if(k&(1<<i)){ g0[c0++] = i; }else{ g1[c1++] = i; } } for(i=0;i<c0;i++){ for(j=0;j<i;j++){ delNum += a[g0[i]][g0[j]]; } } for(i=0;i<c1;i++){ for(j=0;j<i;j++){ delNum += a[g1[i]][g1[j]]; } } if(delNum < minDelNum){ minDelNum = delNum; } } printf("%d\n",minDelNum); } } */ #include<iostream> #define N 15 int a[N][N]; int g0[N]; int g1[N]; int main(){ // freopen("test.txt","r",stdin); int t,n,m,i,j,k,delNum,minDelNum; scanf("%d",&t); while(t--){ minDelNum = INT_MAX; memset(a,0,sizeof(a)); scanf("%d%d",&n,&m); for(k=0;k<m;k++){ scanf("%d%d",&i,&j); a[i][j]++; a[j][i]++; } if(n==1 || m<=1){ printf("0\n"); continue; } int s = 1<<n; int c0,c1; for(k=0;k<s;k++){ c0 = c1 = 0; delNum = 0; g0[c0++] = n-1; for(i=0;i<n-1;i++){ if(k&(1<<i)){ g0[c0++] = i; }else{ g1[c1++] = i; } } for(i=0;i<c0;i++){ for(j=0;j<i;j++){ delNum += a[g0[i]][g0[j]]; } } for(i=0;i<c1;i++){ for(j=0;j<i;j++){ delNum += a[g1[i]][g1[j]]; } } if(delNum < minDelNum){ minDelNum = delNum; } } printf("%d\n",minDelNum); } }