Arbiter
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1463 Accepted Submission(s): 731
Problem Description
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 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.
Input
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).
Output
Output 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
1 3 3 0 1 1 2 2 0
Sample Output
1
题意:给你一个n(n<=15)个点m(m<=300)条边的无向图(可能有重边),求最少删多少条边使图不含奇环。
思路:不含奇环即为二分图,由二分图的性质,我们可以把点集任意分成左右两部分,每一部分去掉内部的边即可变成二分图。
因此利用状压,0表示在左集合,1表示在右集合(反之亦可),然后去除内部的边,取个最小值。
代码:
#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<string>
#include<queue>
#include<vector>
#include<map>
#define maxn 1010
#define INF 1e9+7
using namespace std;
int n,m,k,p,ans,sum;
int lk[maxn][maxn];
int g[maxn],us[maxn];
struct node
{
int tim;
int x,y,xx,yy;
}a[maxn];
void init()
{
memset(lk,0,sizeof(lk));
memset(g,0,sizeof(g));
}
bool find(int x)
{
for(int i=n+1;i<=2*n;i++)
{
if(lk[x][i]&&!us[i])
{
us[i]=1;
if(g[i]==0||find(g[i]))
{
g[i]=x;
return 1;
}
}
}
return 0;
}
vector<int>vc[maxn];
int main()
{
int T,cas=1;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
init();
for(int i=0;i<=n;i++) vc[i].clear();
for(int i=0;i<m;i++){
int x,y;
scanf("%d%d",&x,&y);
vc[x].push_back(y);
}
int ans=m;
m=(1<<n);
int tmp;
for(int i=1;i<m-1;i++)
{
tmp=0;
for(int j=0;j<n;j++)
if(i&(1<<j)){
for(int k=0;k<vc[j].size();k++)
if(i&(1<<vc[j][k])){
tmp++;
}
}
else
{
for(int k=0;k<vc[j].size();k++)
if(!(i&(1<<vc[j][k]))){
tmp++;
}
}
ans=min(ans,tmp);
}
printf("%d\n",ans);
}
return 0;
}