[hdu3118]Arbiter

博客围绕星际飞船Arbiter展开,提到人员搭乘其旅行会因手性改变可能导致精神障碍。核心是一个图论问题,给定含n个点m条边的图,要找出至少删去多少条边使图中无奇环,题解指出无奇环的图是二分图,可枚举二分图集合状态计算答案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Time Limit: 1000/1000 MS (Java/Others)
Memory Limit: 131072/131072 K (Java/Others)

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 TTT, indicating the number of test cases.
The first line of each case consists of two integers NNN and MMM, indicating the number of stars and the number of channels. Each of the next MMM lines indicates one channel (u,vu, vu,v) which means there is a bidirectional channel between star uuu and star vvv (uuu is not equal to vvv).

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&lt;T&lt;=100 &lt; T &lt;= 100<T<=10
0&lt;=N&lt;=150 &lt;= N &lt;= 150<=N<=150&lt;=M&lt;=3000 &lt;= M &lt;= 3000<=M<=300
0&lt;=u,v&lt;N0 &lt;= u, v &lt; N0<=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

题意:
给定一个nnn个点mmm条边的图,问至少删去多少条边使得图中没有奇环。
题解:
没有奇环的图必然是个二分图。由于n很小,所以可以枚举二分图两个集合的状态,然后计算答案即可。

#include<bits/stdc++.h>
using namespace std;
int u[304],v[304],n,m;
bool same(int S,int x,int y){
    return (((S>>x)&1) == ((S>>y)&1));
}
int w33ha(){
    scanf("%d%d",&n,&m);
    int ans=m;
    for(int i=1;i<=m;i++)scanf("%d%d",&u[i],&v[i]);
    for(int S=0;S<(1<<n);S++){
        int now=0;
        for(int i=1;i<=m;i++){
            if(same(S,u[i],v[i]))++now;
        }
        ans=min(ans,now);
    }
    printf("%d\n",ans);
    return 0;
}
int main(){
    int T;scanf("%d",&T);
    while(T--)w33ha();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值