mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 5883_yyecust.cpp
From http://blog.csdn.net/yyecust/article/details/52565788
This commit is contained in:
parent
0befcff854
commit
a53f5205b8
59
HDOJ/5883_yyecust.cpp
Normal file
59
HDOJ/5883_yyecust.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
#include <iostream>
|
||||
#include <cstdio>
|
||||
using namespace std;
|
||||
const int MAXN = 100000;
|
||||
int g[MAXN]; //g[i]表示与i相连的边数
|
||||
int a[MAXN];
|
||||
void solve()
|
||||
{
|
||||
int n, m;
|
||||
scanf("%d%d", &n, &m);
|
||||
for (int i = 0; i < n; i++) {
|
||||
scanf("%d", &a[i]);
|
||||
g[i] = 0;
|
||||
}
|
||||
for (int i = 0; i < m; i++) {
|
||||
int u, v;
|
||||
scanf("%d%d", &u, &v);
|
||||
u--;
|
||||
v--;
|
||||
g[u]++;
|
||||
g[v]++;
|
||||
}
|
||||
int ods = 0; //奇点数
|
||||
int xors = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (g[i] % 2) {
|
||||
ods++;
|
||||
if (g[i] % 3) {
|
||||
xors ^= a[i];
|
||||
}
|
||||
} else {
|
||||
if (g[i] % 4) {
|
||||
xors ^= a[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ods > 2) {
|
||||
puts("Impossible");
|
||||
return;
|
||||
}
|
||||
if (ods == 2) {
|
||||
printf("%d\n", xors);
|
||||
return;
|
||||
}
|
||||
int ans = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
ans = max(ans, xors ^ a[i]);
|
||||
}
|
||||
printf("%d\n", ans);
|
||||
}
|
||||
int main()
|
||||
{
|
||||
//freopen("in.txt", "r", stdin);
|
||||
int t;
|
||||
scanf("%d", &t);
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user