标签:
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <climits> #include <cstring> #include <string> #include <set> #include <map> #include <queue> #include <stack> #include <vector> #include <list> #define rep(i,m,n) for(i=m;i<=n;i++) #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++) #define mod 1000000007 #define inf 0x3f3f3f3f #define vi vector<int> #define pb push_back #define mp make_pair #define fi first #define se second #define ll long long #define pi acos(-1.0) #define pii pair<int,int> #define Lson L, mid, rt<<1 #define Rson mid+1, R, rt<<1|1 const int maxn=1e5+10; using namespace std; ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);} ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;} int n,m,k,t,p[maxn],a[maxn],d[maxn],q[maxn],ans; int find(int x) { return p[x]==x?x:p[x]=find(p[x]); } int main() { int i,j; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); ans=0; memset(d,0,sizeof d); memset(q,0,sizeof q); rep(i,1,n)scanf("%d",&a[i]),p[i]=i; while(m--) { int b,c; scanf("%d%d",&b,&c); d[b]++,d[c]++; int fa=find(b),fb=find(c); if(fa!=fb)p[fa]=fb; } int cnt=0; rep(i,1,n) { int fa=find(i); if(p[fa]!=i&&!q[p[fa]])cnt++,q[p[fa]]=1; } if(cnt>1){puts("Impossible");continue;} else if(cnt==0) { rep(i,1,n)ans=max(ans,a[i]); printf("%d\n",ans); continue; } cnt=0; rep(i,1,n) { if(d[i]&1)cnt++; int now=(d[i]+1)/2; if(now&1)ans^=a[i]; } if(cnt==2) { printf("%d\n",ans); } else if(cnt==0) { ans=0; int ma=0; rep(i,1,n) { int now=(d[i]+1)/2; if(now&1)ans^=a[i]; } rep(i,1,n)if(d[i])ma=max(ma,ans^a[i]); printf("%d\n",ma); } else puts("Impossible"); } //system("Pause"); return 0; }
标签:
原文地址:http://www.cnblogs.com/dyzll/p/5879405.html