You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 1e5 + 7;
int n, m;
int a[N];
int d[N];
int main() {
#ifndef ONLINE_JUDGE
freopen("HDU5883.in", "r", stdin);
#endif
int T;
scanf("%d", &T);
while (T--) {
memset(d, 0, sizeof d);
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
while (m--) {
int a, b;
scanf("%d%d", &a, &b);
d[a]++, d[b]++;
}
// 奇数度点的个数
int cnt = 0;
for (int i = 1; i <= n; i++)
if (d[i] & 1) cnt++;
// 不是0而且个数不是2那么肯定没有欧拉通路也没有欧拉回路
if (cnt && cnt != 2) {
puts("Impossible");
continue;
}
int ans = 0;
for (int i = 1; i <= n; i++) {
int x = (d[i] + 1) >> 1;
if (x & 1) ans ^= a[i];
}
// 如果没有度数为奇数的点,也就是欧拉回路,出发点终点是同一个点,这样会造成起点的权值被异或干掉
// 因为欧拉回路可以以任意一个点做为起点和终点所以需要枚举一遍分别尝试以i这起点找出最大异或值
int res = ans;
if (cnt == 0)
for (int i = 1; i <= n; i++) res = max(res, ans ^ a[i]);
// 输出异或和
printf("%d\n", res);
}
return 0;
}