HDU 5883 The Best Path
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
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.

#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的更多相关文章
- 【刷题】HDU 5883 The Best Path
Problem Description Alice is planning her travel route in a beautiful valley. In this valley, there ...
- HDU 5883 The Best Path (欧拉路或者欧拉回路)
题意: n 个点 m 条无向边的图,找一个欧拉通路/回路使得这个路径所有结点的异或值最大. 析:由欧拉路性质,奇度点数量为0或2.一个节点被进一次出一次,度减2,产生一次贡献,因此节点 i 的贡献为 ...
- HDU - 2290 Find the Path(最短路)
HDU - 2290 Find the Path Time Limit: 5000MS Memory Limit: 64768KB 64bit IO Format: %I64d & % ...
- Hdu 4725 The Shortest Path in Nya Graph (spfa)
题目链接: Hdu 4725 The Shortest Path in Nya Graph 题目描述: 有n个点,m条边,每经过路i需要wi元.并且每一个点都有自己所在的层.一个点都乡里的层需要花费c ...
- 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 ...
- 2015合肥网络赛 HDU 5492 Find a path 动归
HDU 5492 Find a path 题意:给你一个矩阵求一个路径使得 最小. 思路: 方法一:数据特别小,直接枚举权值和(n + m - 1) * aver,更新答案. 方法二:用f[i][j] ...
- The Best Path HDU - 5883(欧拉回路 && 欧拉路径)
The Best Path Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
- HDU 5883 F - The Best Path 欧拉通路 & 欧拉回路
给定一个图,要求选一个点作为起点,然后经过每条边一次,然后把访问过的点异或起来(访问一次就异或一次),然后求最大值. 首先为什么会有最大值这样的分类?就是因为你开始点选择不同,欧拉回路的结果不同,因为 ...
- The Best Path HDU - 5883 欧拉通路
图(无向图或有向图)中恰好通过所有边一次且经过所有顶点的的通路成为欧拉通路,图中恰好通过所有边一次且经过所有顶点的回路称为欧拉回路,具有欧拉回路的图称为欧拉图,具有欧拉通路而无欧拉回路的图称为半欧拉图 ...
随机推荐
- CPU/ABI显示No system images installed for this target的解决方案
CPU/ABI显示No system images installed for this target的解决方案 手动下载image http://www.androiddevtools.cn/ SD ...
- C#中sealed关键字
C#中sealed关键字 1. sealed关键字 当对一个类应用 sealed 修饰符时,此修饰符会阻止其他类从该类继承.类似于Java中final关键字. 在下面的示例中,类 B ...
- hdu 1271 整数对
看了别人的解题报告a了, 大致思路就是 A=a+b*10^k+c*10^(k+1) B=a+c*10^k (在A中取出一位数后) N=A+B=2*a+b*10^k+11*c*10^k 这样就好做了,再 ...
- Android 一个Activity保存它自己的实例
一个Activity保存他自己的实例的作用是,在其他Activity中可以方便的调用该Activity里的方法. 我们可以使用一个静态的变量保存当前Activity的实例,并将其标志为private访 ...
- linux设置和查看环境变量的方法
1. 显示环境变量HOME $ echo $HOME /home/redbooks 2. 设置一个新的环境变量hello $ export HELLO="Hello!" ...
- lintcode: 翻转链表
题目: 翻转链表 翻转一个链表 样例 给出一个链表1->2->3->null,这个翻转后的链表为3->2->1->null 挑战 在原地一次翻转完成 解题: 递归还 ...
- Failed to execute goal.....webxml attribute is required...
maven在打包项目的时候报错 Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-wa ...
- mysqldump常用于MySQL数据库逻辑备份
mysqldump常用于MySQL数据库逻辑备份. 1.各种用法说明 A. 最简单的用法: mysqldump -uroot -pPassword [database name] > [dump ...
- C# 计时器的三种使用方法
在.net中有三种计时器,一是System.Windows.Forms命名空间下的Timer控件,它直接继承自Componet;二是System.Timers命名空间下的Timer类. Timer控件 ...
- BZOJ 1004 Cards(Burnside引理+DP)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1004 题意:三种颜色的扑克牌各有Sr,Sb,Sg张.给出m种置换.两种染色方案在某种置换 ...