Arbiter
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1496 Accepted Submission(s): 748
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 t
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define sc scanf
#define ls rt << 1
#define rs ls | 1
#define Min(x, y) x = min(x, y)
#define Max(x, y) x = max(x, y)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define MEM(x, b) memset(x, b, sizeof(x))
#define lowbit(x) ((x) & (-x))
#define P2(x) ((x) * (x))
typedef long long ll;
const int MOD = 1e9 + 7;
const int MAXN = 2e3 + 10;
const int INF = 0x3f3f3f3f;
inline ll fpow(ll a, ll b){ ll r = 1, t = a; while (b){ if (b & 1)r = (r*t) % MOD; b >>= 1; t = (t*t) % MOD; }return r; }
struct node
{
int u, v;
}p[MAXN];
int n, m, T;
int main()
{
cin >> T;
while (T--) {
sc("%d %d", &n, &m);
int cnt = 0, ans = INF;
for (int i = 0; i < m; i++) sc("%d %d", &p[i].u, &p[i].v);
for (int i = 0; i < (1 << n); i++) {
cnt = 0;
for (int j = 0; j < m; j++) {
int ui = p[j].u, vi = p[j].v;
ui = (i >> ui) & 1, vi = (i >> vi) & 1;
if (ui == vi) cnt++;
}
Min(ans, cnt);
}
cout << ans << endl;
}
return 0;
}
wo stars.
Sample Input
1 3 3 0 1 1 2 2 0
Sample Output
1
题目大意 : 输入一个无向图, 可能有重边, 输出你可以删的最少的边, 使图中没有奇环
思路 :说到奇环, 不难想到要用到二分图的知识, 在二分图中不存在奇环, 这是充要条件, 题目给的点又非常小, 所以直接状态压缩, 状态为1和状态为0的分别为二分图的两个集合, 如果图中存在的边是一个集合, 说明不是二分图, 最后取最小值即可
Accepted code