题干:

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?

Input

The 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.

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

题目大意:

一个图,每一条边必须且只能经过一次,写出经过点的路径,类似于p1->p2->p1,求一条路径,使得路径的点的异或和最大,求这个最大值。

解题报告:

首先判断联通,然后看是否有欧拉回路或者欧拉通路,然后两种情况分别判断。如果都没有则输出impossible。

AC代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cctype>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int n,m,in[maxn];
int a[maxn];
vector<int> vv[maxn];
int main()
{int t,i,j,k,cnt,u,v,ans=0;int sum=0;cin>>t;    while(t--){scanf("%d%d",&n,&m);cnt=0;for(i=1;i<=n;i++){scanf("%d",&a[i]);in[i]=0;vv[i].clear();}for(i=1;i<=m;i++){scanf("%d%d",&u,&v);vv[u].push_back(v);vv[v].push_back(u);in[u]++; in[v]++;}for(i=1;i<=n;i++){// cout<<i<<":"<<in[i]<<endl;cnt+=(in[i]&1);}if(cnt==1||cnt>2){puts("Impossible");continue;}ans=0;if(cnt){for(i=1;i<=n;i++){if(in[i]&1){ans^=a[i];if(((in[i]-1)/2)%2)ans^=a[i];}else if((in[i]/2)%2)ans^=a[i];}}else {sum=0;for(i=1;i<=n;i++){if((in[i]/2)%2)sum^=a[i];}for(i=1;i<=n;i++)ans=max(ans,sum^a[i]);}printf("%d\n",ans);}return 0;
}

【HDU - 5883】The Best Path(判断欧拉回路)相关推荐

  1. 【python初级】os.path.isfile(path)判断路径是否为文件

    [python初级]os.path.isfile判断路径是否为文件 背景 示例 背景 os.path.isfile(path)判断路径是否为文件. import os help(os.path.isf ...

  2. hdu 1317 XYZZY【Bellheman_ford 判断正环小应用】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1317 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  3. HDU 6223 Infinite Fraction Path

    链接 http://acm.hdu.edu.cn/showproblem.php?pid=6223 Problem Description The ant Welly now dedicates hi ...

  4. HDU 4850 Wow! Such String! 【欧拉回路】【一顿乱构造】

    link: http://acm.hdu.edu.cn/showproblem.php?pid=4850 题解: 每个长度为3的字符串当一个节点,每个节点连出26条边,代表给长度为3的字符串吼添加'a ...

  5. hdu 4725 The Shortest Path in Nya Graph(建图+优先队列dijstra)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4725 题意:有n个点和n层,m条边,每一层的任意一个点都可以花费固定的值到下一层或者上一层的任意点 然 ...

  6. HDU 1269 迷宫城堡 -- 强连通图判断

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1269 图的强连通分量 http://baike.baidu.com/link?url=NqsmNsGC ...

  7. HDU - 4725 The Shortest Path in Nya Graph(最短路+思维)

    题目链接:点击查看 题目大意:给定n个点,在一般的基础上给每个点一个维度,也就是多了一个参数表示所在的层次,现在已知: X层的点可以通过增加权值C到达X-1层或X+1层中的任何一个点 给定m个已经形成 ...

  8. HDU 2224 The shortest path

    传送门 属于动态规划.TSP(旅行商)问题的简化版本,双调旅行商问题.时间复杂度O(n^2). 可以参考这个. 给你平面上n个点的坐标,这些点的x坐标依次增大,让你找一条满足这样的性质的最短的路:从1 ...

  9. hdu 3600 Simple Puzzle (判断N 数码是否有解)

    分析: 当N为奇数时奇偶同性可互达,N为偶数时,逆序数之和sum加上空格所在行距目标空格行的距离dis之和要和终点状态逆序数同奇偶 View Code #include<iostream> ...

最新文章

  1. Leangoo Talk第一期——Scrum与OKR融合实践
  2. Linking Containers Together
  3. android状态机实现原理
  4. linux 的date命令详解,linux之date命令详解
  5. centos7 安装cacti
  6. 格罗方德起诉台积电侵犯16项专利、影响巨大;中兴通讯与印尼Smartfren展开合作;网传FB开发新通讯应用Threads……...
  7. CTF【解密】字符串flag被加密成已知新字符串,请解密出flag,可以使用Python解码出WriteUp
  8. myEclipse背景控制插件方案 内附使用说明
  9. PostgreSQL中常见的14个用户安全配置
  10. php无法连通mysql_怎么解决php无法连接mysql的问题
  11. ant Design表单验证笔记
  12. 数字电路与微型计算机原理,电子科技大学1999年考研真题-微机原理与数字电路...
  13. 如何强大且优雅的搞定Linux文件系统,值得一读!
  14. 统计一句话中每个字母出现的次数
  15. 关于Chromium Embedded Framework (CEF)的编译
  16. 如何配置php session使用redis集群
  17. 开源BI工具对比(一):BI介绍
  18. c语言ch1与ch2什么意思,ch1和ch2是什么意思
  19. android 4.4.4最新微信,微信旧版本安卓4.4.4可用
  20. RN导入高德地图定位的用法实例

热门文章

  1. [dp]leetcode 746. Min Cost Climbing Stairs
  2. 【数据结构与算法】排序优化
  3. 16位计算机cpu电路图,简单16位CPU设计.doc
  4. android按钮控件常见问题,Android的基本控件和Activity的应用总结
  5. ireport 循环_ireport5.6.0分组显示
  6. java值参_JAVA赋值和传参理解
  7. 10以内的分解与组成怎么教_【一年级数学】(上)10以内的分与合技巧及练习题...
  8. php 时间错误,PHP xdebug调试trace记录时间错误
  9. mysql 线程池 下载_java线程池实现批量下载文件
  10. 怎么安装python3.6.5_Centos7 安装Python3.6.5