Arbiter
Arbiter is a kind of starship in theStarCraft science-fiction series. TheArbiter-class starship is a Protoss warship specializing in providing psychicsupport. Arbiters were crewed exclusively by Judicators; unlike otherwarships that were manned predominantly by Templar. The Judicator used theArbiter as a base to provide support using space-time manipulation.
Arbiters could weaken space-time, tearingrifts in the fabric of space-time, creating a vortex linking another locationto the Arbiter’s location. This could be used to move personnel over longdistances between stars.
In the meantime of widely used Arbiter totransfer, KMXS, the captain of one Arbiter, was warning thatsome 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, eitherleft-handed or right-handed. Actually all the persons must live with the foodwhich has the same chirality. When one person took Arbiter from one star toanother one, hischirality will be changed (from left-handed toright-handed or from right-handed to left-handed). If a person took a long tripand finally got back to his own star, however, his chirality might be changed to the opposite state other thanhis original, which would cause fatal mental disorder, or even death.
KMXS has the channels map amongthe starts and he need to prohibit minimum number of channels from traveling so that wherevera person starts his traveling from when he gets his original star he’ll be safe.KMXS turns to your help.
题目的意思大概是:给你一些点以及一些边,若存在奇数环,则在这环内传送会导致手性错误。 求去掉最少的边,使该图不存在奇数环。
题解:
用到了这样的一条性质
如图所示 ,只用把同一个集合内的边删掉就好了。。
因为数据N最大只有15. 所以,直接用二进制存就好了。
代码:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m;
const int N=20;
int g[N][N];
int total(int u){
int ans=0;
for(int i=0;i<n;i++)
if(u&(1<<i))
for(int j=i+1;j<n;j++)
if(u&(1<<j)){
ans+=g[i][j];
}
//printf("u=%d ans=%d\n",u,ans);
return ans;
}
void solve(){
int ope=(1<<n)-1;
int ans=m;
for(int i=0;i<=ope;i++){
int tmp=ope^i;
tmp=total(i)+total(tmp);
ans=min(tmp,ans);
}
printf("%d\n",ans);
}
int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%d %d",&n,&m);
memset(g,0,sizeof(g));
for(int i=0,u,v;i<m;i++){
scanf("%d %d",&u,&v);
g[u][v]++;g[v][u]++;
}
solve();
}
return 0;
}