Problem Description

Alice is planning her travel route in a beautiful valley. In this valley, there are N lakes, and M rivers linking these lakes. Alice wants to start her trip from one lake, and enjoys the landscape by boat. That means she need to set up a path which go through every river exactly once. In addition, Alice has a specific number (a1,a2,...,an) for each lake. If the path she finds is \(P_0 \rightarrow P_1 \rightarrow ... \rightarrow P_t\) , the lucky number of this trip would be \(a_{P_0} \quad XOR \quad a_{P_1} \quad XOR \quad... \quad XOR \quad a_{P_t}\) . She want to make this number as large as possible. Can you help her?

Input

The first line of input contains an integer t, the number of test cases. t test cases follow.

For each test case, in the first line there are two positive integers N (N≤100000) and M (M≤500000), as described above. The i-th line of the next N lines contains an integer ai(∀i,0≤ai≤10000) representing the number of the i-th lake.

The i-th line of the next M lines contains two integers ui and vi representing the i-th river between the ui-th lake and vi-th lake. It is possible that ui=vi.

Output

For each test cases, output the largest lucky number. If it dose not have any path, output "Impossible".

Sample Input

2

3 2

3

4

5

1 2

2 3

4 3

1

2

3

4

1 2

2 3

2 4

Sample Output

2

Impossible

Description(CHN)

给你一个无向图,每个点有权值,你要从某一个点出发,使得一笔画经过所有的路,且使得经过的节点的权值XOR运算最大

Solution

对于一个图,如果奇度数点数不为0也不为2,那么无解

如果为2,则欧拉路径固定,每个点经过的次数为它的度数/2,直接算就可以了

如果为0,即存在欧拉回路,这种情况相较于上一种情况就是起点多经过了一次,因为要回到起点,所以枚举起点,chkmax就好了

#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
const int MAXN=100000+10;
int T,n,m,val[MAXN],d[MAXN],sum[2],ans,now;
template<typename T> inline void read(T &x)
{
T data=0,w=1;
char ch=0;
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')w=-1,ch=getchar();
while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
int main()
{
read(T);
while(T--)
{
read(n);read(m);
for(register int i=1;i<=n;++i)read(val[i]),d[i]=0;
for(register int i=1;i<=m;++i)
{
int u,v;read(u);read(v);
d[u]++;d[v]++;
}
sum[0]=sum[1]=0;
for(register int i=1;i<=n;++i)sum[d[i]&1]++;
if(sum[1]!=0&&sum[1]!=2)
{
puts("Impossible");
continue;
}
ans=now=0;
for(register int i=1;i<=n;++i)
if((d[i]>>1)&1)now^=val[i];
if(sum[1]==2)
{
for(register int i=1;i<=n;++i)
if(d[i]&1)now^=val[i];
ans=now;
}
else
for(register int i=1;i<=n;++i)chkmax(ans,now^val[i]);
write(ans,'\n');
}
return 0;
}

【刷题】HDU 5883 The Best Path的更多相关文章

  1. HDU 5883 The Best Path

    The Best Path Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tot ...

  2. HDU 5883 The Best Path (欧拉路或者欧拉回路)

    题意: n 个点 m 条无向边的图,找一个欧拉通路/回路使得这个路径所有结点的异或值最大. 析:由欧拉路性质,奇度点数量为0或2.一个节点被进一次出一次,度减2,产生一次贡献,因此节点 i 的贡献为 ...

  3. 【刷题-PAT】A1126 Eulerian Path (25 分)

    1126 Eulerian Path (25 分) In graph theory, an Eulerian path is a path in a graph which visits every ...

  4. HDU 自动刷题机 Auto AC (轻轻松松进入HDU首页)

    前言: 在写这篇文章之前,首先感谢给我思路以及帮助过我的学长们 以下4篇博客都是学长原创,其中有很多有用的,值得学习的东西,希望能够帮到大家! 1.手把手教你用C++ 写ACM自动刷题神器(冲入HDU ...

  5. 手把手教你用C++ 写ACM自动刷题神器(冲入HDU首页)

    转载注明原地址:http://blog.csdn.net/nk_test/article/details/49497017 少年,作为苦练ACM,通宵刷题的你 是不是想着有一天能够荣登各大OJ榜首,俯 ...

  6. 教你用python写:HDU刷题神器

    声明:本文以学习为目的,请不要影响他人正常判题 HDU刷题神器,早已被前辈们做出来了,不过没有见过用python写的.大一的时候见识了学长写这个,当时还是一脸懵逼,只知道这玩意儿好屌-.时隔一年,决定 ...

  7. 刷题64. Minimum Path Sum

    一.题目说明 题目64. Minimum Path Sum,给一个m*n矩阵,每个元素的值非负,计算从左上角到右下角的最小路径和.难度是Medium! 二.我的解答 乍一看,这个是计算最短路径的,迪杰 ...

  8. 【刷题】HDU 2222 Keywords Search

    Problem Description In the modern time, Search engine came into the life of everybody like Google, B ...

  9. leetcode刷题总结一

    大四狗找工作,要刷题了,leetcode上面题目比较适合面试算法类题目,也不纯粹为了蒙题,锻炼一下面试类型的思维 Single Number: 有N个数,其中只有一个数出现了一次,其他都是两次,找出那 ...

随机推荐

  1. Java IO详解(七)------随机访问文件流

    File 类的介绍:http://www.cnblogs.com/ysocean/p/6851878.html Java IO 流的分类介绍:http://www.cnblogs.com/ysocea ...

  2. 关于mydumper的.metadata文件丢失

    今天要进行MySQL的数据迁移,所以把数据库通过mydumper工具备份的文件解压后.通过myloader进行导入 可是导入的时间出现这个报错: ** (myloader:766): CRITICAL ...

  3. c# 无边框窗体的边框阴影

    Windows API: using System; using System.Collections.Generic; using System.ComponentModel; using Syst ...

  4. WebService快速上手

    一.WebService是什么? 核心特征:跨语言.跨平台.远程调用[如果是本地系统交互,使用rpc或者com技术就行] soap:HTTP + XML [基于Http的xml格式数据交互] wsdl ...

  5. [python]记录Windows下安装matplot的经历

    最近学习在看<机器学习实战>一书,第二章的时候要用到Natplotlib画图,于是便开始安装Matplotlib.本文所用到的所有安装包都可以在文末的链接中找到. 首先从Matplotli ...

  6. 编程语法分析之“优先级”和“结合律”

    上节<编程语法分析之从表达式说起>中说到表达式,他的主要作用就是返回一个值!那这个值具体是多少,就要看表达式的整个运算过程.要理解表达式的运算过程就必须了解"优先级"和 ...

  7. 【php增删改查实例】第一节 - PHP开发环境配置

    最近需要使用PHP,于是把平时的积累整理一下,就有了这个教程. 首先是环境配置: 1.操作系统:windos7 2.后台:PHP 3.前台:Html + js + css 4.数据库:MYSQL 5. ...

  8. 【ORACLE】碎片整理

    alter table test enable row movement; alter table test shrink space; execute dbms_stats.gather_table ...

  9. 虚拟机console基础环境部署——工作目录准备

    1. 概述2. 相关约定2.1 删除旧文件2.2 创建全局共享文件目录2.3 创建全局软件安装目录2.4 创建数据放置目录3. 总结 1. 概述 上述博客中,已经为console最小化安装了操作系统. ...

  10. 《杜增强讲Unity之Tanks坦克大战》9-发射子弹时蓄力

    9 发射子弹时蓄力 实现效果如下   image 按下开火键(坦克1为空格键)重置力为最小力,一直按着的时候蓄力,抬起的时候发射.如果按着的时候蓄力到最大,则自动发射,此时在抬起则不会重复发射. 首先 ...