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. Junit测试和反射

    Junit单元测试 测试分类 黑盒测试:不需要写代码,给输入值,看程序能否得到输出期望值. 白盒测试:需要些代码,关注程序具体的执行流程. Junit的使用 步骤 定义一个测试类(测试用例). 定义测 ...

  2. Nginx架构赏析

    淘宝的某位大佬曾经做过测试,在一台24G内存的机器上,Nginx的最大并发连接数达到了200万.同学们听到这个结论后,是不是被Nginx的超高性能深深折服了,它内部的架构设计究竟是怎么样的呢?这篇文章 ...

  3. WPF权限控制——【1】界面布局

    本来就不怎么喜欢写博客,好不容易申请了博客园的账号,迈出了先前没有跨越的第一步:转眼间几年的时间就过去了,还是空空如也.今天的心境是这样的,发现wpf相关的资料及源码实在不多,就想写下随笔:一方面是自 ...

  4. Infrastructure as Code 行为驱动开发指南 https://www.ibm.com/developerworks/cn/devops/d-bbd-guide-iac/index.html

    Infrastructure as Code 行为驱动开发指南 https://www.ibm.com/developerworks/cn/devops/d-bbd-guide-iac/index.h ...

  5. 公共错误码 - 支付宝开放平台 https://opendocs.alipay.com/open/common/105806

    公共错误码 - 支付宝开放平台 https://opendocs.alipay.com/open/common/105806

  6. 苹果 M1 芯片 OpenSSL 性能测试

    Apple M1(MacBook Air 2020) type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes md2 0.00 0.00 0.00 ...

  7. loj10007线段

    题目描述 数轴上有 n 条线段,选取其中 k 条线段使得这 k 条线段两两没有重合部分,问 k 最大为多少. 输入格式 第一行为一个正整数 n: 在接下来的 n 行中,每行有 2 个数 a_i,b_i ...

  8. loj10153二叉苹果树

    有一棵二叉苹果树,如果数字有分叉,一定是分两叉,即没有只有一个儿子的节点.这棵树共 N 个节点,标号 1 至 N,树根编号一定为 1. 我们用一根树枝两端连接的节点编号描述一根树枝的位置.一棵有四根树 ...

  9. 网页开发(HTML 基础)

    网页的标准是W3C,目前模式是HTML.CSS和JavaScript. HTML,全称"Hyper Text Markup Language(超文本标记语言)",简单来说,网页就是 ...

  10. python中字符串的翻转(方法总结)

    Python翻转字符串(reverse string), 一共包含5种方法, 其中第一种最简单, 即步长为-1, 输出字符串; 方法如下 5种方法的比较: 1. 简单的步长为-1, 即字符串的翻转(常 ...