HDU 3118 Arbiter 二分判断

73 篇文章 21 订阅
56 篇文章 0 订阅

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.

 

题目的意思大概是:给你一些点以及一些边,若存在奇数环,则在这环内传送会导致手性错误。  求去掉最少的边,使该图不存在奇数环。

 

题解:

 

用到了这样的一条性质

无向图G为二分图的充分必要条件是,G至少有两个顶点,且其所有回路的长度均为偶数。

 

 

如图所示 ,只用把同一个集合内的边删掉就好了。。

因为数据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;
}


 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值