Alice is planning her travel route in a beautiful valley. In this valley, there are NN lakes, and MM 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,...,ana1,a2,...,an) for each lake. If the path she finds is P0→P1→...→PtP0→P1→...→Pt, the lucky number of this trip would be aP0XORaP1XOR...XORaPtaP0XORaP1XOR...XORaPt. She want to make this number as large as possible. Can you help her?

InputThe first line of input contains an integer tt, the number of test cases. tt test cases follow. 

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

The ii-th line of the next MM lines contains two integers uiui and vivi representing the ii-th river between the uiui-th lake and vivi-th lake. It is possible that ui=viui=vi.OutputFor 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

题意:t组数据,n个点,m条边。每个点都有权值。问这个图能不能构成欧拉通路(或回路。如果能,求从起点异或到终点的值中的最大值。

解题思路:判断下能否构成,如果能构成通路,则只有一条路径,如果能构成回路,需要枚举起点。注意异或的时候不需要重现路径,因为
a^a=0所以只要通过某个点偶数次,则这个点就不需要异或。因为在通路中起点和终点的度为奇数,所以取值时应该向上取整。如样例1中
1是起点,度数为1,通过该点的次数也为1,所以应是(nu[i]+1)/2%2才能正确判断通过该点的次数是否为奇数。
而如果是回路,则通过起点的次数要通路多一次,终点的次数不变。(不明白的话可画一个简单的例子模拟一下
所以只需要遍历所有点,取对每个点异或之后的最大值便是答案。

ac代码:
 1 #include <cstdio>
2 #include <iostream>
3 #include <cmath>
4 #include <cstring>
5 #include <algorithm>
6 #include <vector>
7 #define ll long long
8 using namespace std;
9 const int maxn = 1e5+10;
10 int nu[maxn];
11 int val[maxn];
12 int main()
13 {
14 int t,n,m;
15 scanf("%d",&t);
16 while(t--)
17 {
18 memset(nu,0,sizeof(nu));
19 scanf("%d%d",&n,&m);
20 for(int i=1;i<=n;++i)
21 {
22 scanf("%d",&val[i]);
23 }
24 int u,v;
25 for(int i=1;i<=m;++i)
26 {
27 scanf("%d%d",&u,&v);
28 nu[u]++;
29 nu[v]++;
30 }
31 int cnt=0;
32 for(int i=1;i<=n;++i)
33 {
34 if(nu[i]%2==1)
35 {
36 cnt++;
37 }
38 }
39 // cout<<cnt<<endl;
40 if(cnt!=0 && cnt!=2)
41 {
42 printf("Impossible\n");
43 continue;
44 }
45 else
46 {
47 int ans=0;
48 for(int i=1;i<=n;++i)
49 {
50 if((nu[i]+1)/2%2==1)
51 ans^=val[i];
52 }
53 if(cnt==0)
54 {
55 int u=ans;
56 for(int i=1;i<=n;++i)
57 {
58 ans=max(ans,u^val[i]);
59 }
60 }
61 printf("%d\n",ans);
62 }
63 }
64 }

hdu 5883的更多相关文章

  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

    Problem Description Alice is planning her travel route in a beautiful valley. In this valley, there ...

  3. The Best Path HDU - 5883(欧拉回路 && 欧拉路径)

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

  4. HDU 5883 F - The Best Path 欧拉通路 & 欧拉回路

    给定一个图,要求选一个点作为起点,然后经过每条边一次,然后把访问过的点异或起来(访问一次就异或一次),然后求最大值. 首先为什么会有最大值这样的分类?就是因为你开始点选择不同,欧拉回路的结果不同,因为 ...

  5. The Best Path HDU - 5883 欧拉通路

    图(无向图或有向图)中恰好通过所有边一次且经过所有顶点的的通路成为欧拉通路,图中恰好通过所有边一次且经过所有顶点的回路称为欧拉回路,具有欧拉回路的图称为欧拉图,具有欧拉通路而无欧拉回路的图称为半欧拉图 ...

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

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

  7. HDU 5883 欧拉路径异或值最大 水题

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

  8. HDU 5883 欧拉回路

    题面: 思路: 这里面有坑啊啊啊-.. 先普及一下姿势: 判断无向图欧拉路的方法: 图连通,只有两个顶点是奇数度,其余都是偶数度的. 判断无向图欧拉回路的方法: 图连通,所有顶点都是偶数度. 重点:图 ...

  9. 【2016 ACM/ICPC Asia Regional Qingdao Online】

    [ HDU 5878 ] I Count Two Three 考虑极端,1e9就是2的30次方,3的17次方,5的12次方,7的10次方. 而且,不超过1e9的乘积不过5000多个,于是预处理出来,然 ...

随机推荐

  1. luogu P2198 杀蚂蚁

    题目描述 经过小FF的研究,他发现蚂蚁们每次都走同一条长度为n个单位的路线进攻, 且蚂蚁们的经过一个单位长度所需的时间为T秒.也就是说,只要小FF在条路线上布防且给蚂蚁造成沉痛伤害就能阻止蚂蚁的进军. ...

  2. Seata RPC 模块的重构之路

    简介: RPC 模块是我最初研究 Seata 源码开始的地方,因此我对 Seata 的 RPC 模块有过一些深刻研究,在我研究了一番后,发现 RPC 模块中的代码需要进行优化,使得代码更加优雅,交互逻 ...

  3. mybatis缓存源码分析之浅谈缓存设计

    本文是关于mybatis缓存模块设计的读后感,关于缓存的思考,关于mybatis的缓存源码详细分析在另一篇文章:https://www.cnblogs.com/gmt-hao/p/12448896.h ...

  4. python生成器 递归

    生成器 生成器:只要函数体内出现yield关键字,那么再执行函数就不会执行函数代码,会得到一个结果,该结果就是生成器   生成器就是迭代器   yield的功能 1.yield为我们提供了一种自定义迭 ...

  5. selenium浏览器弹出框alert 操作

    1.简介 在WebDriver中要处理JS生成的alert.confirm以及prompt,需要 switch_to.alert() 来选取(定位)警告弹窗,在对弹窗进行关闭.输入等信息操作. 2.操 ...

  6. 如何应对C语言内存泄露! 华为开发者社区 2020-09-29

    如何应对C语言内存泄露! 华为开发者社区 2020-09-29

  7. CF1209A

    所谓染色,并使同颜色数都能被当前颜色中最小的数整除 也就是说,把能被某个数整除的所有数放在一起为一组,问共有几组 开始我想写个并查集但是很懒,看数据范围小的可怜,那我们写个暴力看看 因为每组的共因数都 ...

  8. exkmp(Z函数) 笔记

    exkmp 用于求解这样的问题: 求文本串 \(T\) 的每一个后缀与模式串 \(M\) 的匹配长度(即最长公共前缀长度).特别的,取 \(M=T\),得到的这个长度被称为 \(Z\) 函数.&quo ...

  9. 小米和MAC触摸板手势汇总

    小米的触摸手势: 左键:单指单击 右键:双指单击 选取并打开:单指双击 滚动页面:双指 移动 拖拽项目:双击并拖拽 放大/缩小:双指张开,双指捏合 MAC触摸板手势: http://www.cr173 ...

  10. MariaDB数据库---主从复制,galera架构

    主从复制 补充一点:⑤slave端的IO thread 将从master端请求来的二进制日志文件中的内容存储到relay_log(中继日志)中 图片来源:https://www.cnblogs.com ...