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. C# 面向对象之概念理解

    什么是对象? <韦氏大词典>中对对象定义: (1)某种可为人所感知的物质. (2)思维.感受或动作所作用的物质或精神体. ----说白了万物皆对象 熟悉的对象描述: 对象就是客观世界中的物 ...

  2. the-type-java-lang-charsequence-cannot-be-resolved-in-package-declaration

    http://stackoverflow.com/questions/24301986/the-type-java-lang-charsequence-cannot-be-resolved-in-pa ...

  3. ***常见复杂SQL语句(含统计类SQL)

    1.SQL统计某字段的出现次数 比如统计某个表中,姓名出现的次数:select name,count(*) from biao group by name having count(*) > 2 ...

  4. Code::Blocks生成的EXE文件执行错误解决:The program can't start because libgcc_s_dw2-1.dll is missing

    想用C++弄个简单东东,看有没有可行性, 开发软件,微软的太大太肿,就选用了Code::Blocks. 测试HELLO时,在工程环境中没问题的,但生成的EXE执行有问题, 报什么 libgcc_s_d ...

  5. Windows JDK环境变量的配置

    下载JDK:http://www.oracle.com/technetwork/java/javase/downloads/index.html 安装 计算机-->属性-->高级系统设置- ...

  6. mysql级联更新的两种方式:触发器更新和外键

    1.mysql级联更新有两种方式:触发器更新和外键更新. 2.触发器更新和外键更新的目的都是为了保证数据完整性. 我们通常有这样的需求:删除表Table 1中记录,需要同时删除其它表中与Table 1 ...

  7. iOS 开发-- Runtime 1小时入门教程

    1小时让你知道什么是Objective-C Runtime,并对它有一定的基本了解,可以在开发过程中运用自如. 三.Objective-C Runtime到底是什么东西? 简而言之,Objective ...

  8. [iOS]iPhone进行真机测试(基础版)

    买完688个人开发者账号之后,如何进行真机测试呢??看下面 1.打开https://developer.apple.com 然后,输入我们买过688点那个App ID帐号和密码哦!!一定是要支付过的! ...

  9. 关于Linux的时间与时区

    转:http://linux.chinaunix.net/techdoc/beginner/2007/06/22/960790.shtml 首先要说明的是我的系统是fedora,其他系统可能不完全相同 ...

  10. 如何查看linux是32位还是64位

    可以用命令“getconf LONG_BIT”查看,如果返回的结果是32则说明是32位,返回的结果是64则说明是64位. 此外还可以使用命令“uname -a”查看,输出的结果中,如果有x86_64就 ...