The Best Path

Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 852    Accepted Submission(s): 359
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 P0→P1→...→Pt, the lucky number of this trip would be aP0 XOR aP1 XOR ... XOR aPt. 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
 
Source
 
 
 
解析:
 
 
 
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXN = 100000+5;
int a[MAXN];
int degree[MAXN];
int n, m; void solve()
{
memset(degree, 0, sizeof(degree));
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
int u, v;
while(m--){
scanf("%d%d", &u, &v);
++degree[u];
++degree[v];
}
int odd_sum = 0;
for(int i = 1; i <= n; ++i){
if(degree[i]&1)
++odd_sum;
}
if(!(odd_sum == 0 || odd_sum == 2)){
printf("Impossible\n");
return;
}
int val = 0;
for(int i = 1; i <= n; ++i){
if((degree[i]/2)&1)
val ^= a[i];
}
if(odd_sum == 0){
int res = 0xffffffff;
for(int i = 1; i <= n; ++i){
if(degree[i] != 0)
res = max(res, val^a[i]);
}
printf("%d\n", res);
}
else{
int s = 0, e = 0;
for(int i = 1; i <= n; ++i){
if(degree[i]&1){
if(s == 0){
s = i;
}
else{
e = i;
break;
}
}
}
int res = val^a[s]^a[e];
printf("%d\n", res);
}
} int main()
{
int t;
scanf("%d", &t);
while(t--){
solve();
}
return 0;
}

  

HDU 5883 The Best Path的更多相关文章

  1. 【刷题】HDU 5883 The Best Path

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

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

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

  3. HDU - 2290 Find the Path(最短路)

    HDU - 2290 Find the Path Time Limit: 5000MS   Memory Limit: 64768KB   64bit IO Format: %I64d & % ...

  4. Hdu 4725 The Shortest Path in Nya Graph (spfa)

    题目链接: Hdu 4725 The Shortest Path in Nya Graph 题目描述: 有n个点,m条边,每经过路i需要wi元.并且每一个点都有自己所在的层.一个点都乡里的层需要花费c ...

  5. HDU 4725 The Shortest Path in Nya Graph [构造 + 最短路]

    HDU - 4725 The Shortest Path in Nya Graph http://acm.hdu.edu.cn/showproblem.php?pid=4725 This is a v ...

  6. 2015合肥网络赛 HDU 5492 Find a path 动归

    HDU 5492 Find a path 题意:给你一个矩阵求一个路径使得 最小. 思路: 方法一:数据特别小,直接枚举权值和(n + m - 1) * aver,更新答案. 方法二:用f[i][j] ...

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

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

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

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

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

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

随机推荐

  1. POJ3461 Oulipo KMP算法

    这个算法去年的这个时候就已经听过了,看毛片算法哈哈..不过理解它确实花了我很久的时间..以致于我一直很排斥字符串的学习,因为总觉得太难了,但是有些硬骨头还是要啃的,这个寒假就啃啃字符串还有一些别的东西 ...

  2. **bootstrap常见常用样式总结

    1.水平居中 用 .text-center 类

  3. SDUT1591交叉排序

    http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=1591&cid=1187 #include<cstdio> #include& ...

  4. 李洪强iOS开发支付集成之支付宝支付

    iOS开发支付集成之支付宝支付 下载支付宝SDK 首先是开发包下载,还是比较难发现的,网上以前文章中的链接都打不开,我找了好久才找到的.最新的地址在这里(注意的是下载出来的SDK包里面并没有传说中的开 ...

  5. *[codility]MaxDoubleSliceSum

    https://codility.com/demo/take-sample-test/max_double_slice_sum 两个最大子段和相拼接,从前和从后都扫一遍.注意其中一段可以为0.还有最后 ...

  6. iOS 中有用的开源库

    youtube下载神器:https://github.com/rg3/youtube-dl vim插件:https://github.com/Valloric/YouCompleteMe vim插件配 ...

  7. Dictionary<Key,Value>的用法

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. C# 常用对象的的修饰符

    class(类) 1.internal 表示类只能在当然程序集中访问,类默认修饰符 2.public 表示所有地方都可以访问,与internal是互斥的 3.abstract 抽象类,不能被实例化,只 ...

  9. Java API —— JDK5新特性

    JDK5新特性         自动拆装箱.泛型.增强for.静态导入.可变参数.枚举   1.增强for概述         1)简化数组和Collection集合的遍历         2)格式: ...

  10. Android权限安全(7)binder,service,zygote安全相关简介

    binder 提供服务的service中的binder thread 检查调用者的uid 不是root,system就异常. service 也检查调用者的uid 不是root,system,只能注册 ...