标签:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAXN = 100000+5; int a[MAXN]; int degree[MAXN]; int n, m; void solve() { memset(degree, 0, sizeof(degree)); scanf("%d%d", &n, &m); for(int i = 1; i <= n; ++i) scanf("%d", &a[i]); int u, v; while(m--){ scanf("%d%d", &u, &v); ++degree[u]; ++degree[v]; } int odd_sum = 0; for(int i = 1; i <= n; ++i){ if(degree[i]&1) ++odd_sum; } if(!(odd_sum == 0 || odd_sum == 2)){ printf("Impossible\n"); return; } int val = 0; for(int i = 1; i <= n; ++i){ if((degree[i]/2)&1) val ^= a[i]; } if(odd_sum == 0){ int res = 0xffffffff; for(int i = 1; i <= n; ++i){ if(degree[i] != 0) res = max(res, val^a[i]); } printf("%d\n", res); } else{ int s = 0, e = 0; for(int i = 1; i <= n; ++i){ if(degree[i]&1){ if(s == 0){ s = i; } else{ e = i; break; } } } int res = val^a[s]^a[e]; printf("%d\n", res); } } int main() { int t; scanf("%d", &t); while(t--){ solve(); } return 0; }
标签:
原文地址:http://www.cnblogs.com/inmoonlight/p/5901526.html