The Best Path

Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 2104    Accepted Submission(s): 841

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 aP0XORaP1XOR...XORaPt. 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

解析 先判断图是否只有一个连通块   然后判断是否存在欧拉回路或者路径  欧拉路径每个点经过  (度数+1)/2 次  欧拉回路也一样  但是起点多走一次   每个点都可以作为起点

所以直接枚举取最大值就好了。

AC代码

 #include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+;
int a[maxn],du[maxn],par[maxn];
int _find(int x)
{
return x==par[x]?x:par[x]=_find(par[x]);
}
void unio(int a,int b)
{
int ra=_find(a);
int rb=_find(b);
if(ra!=rb) par[rb]=ra;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
par[i]=i;du[i]=;
scanf("%d",&a[i]);
}
for(int i=;i<m;i++)
{
int u,v;
scanf("%d%d",&u,&v);
unio(u,v);
du[u]++,du[v]++;
}
int sum=,flag=;
for(int i=;i<=n;i++)
{
if(du[i]&)sum++;
if(par[i]==i)flag++;
}
if(sum>||flag>)
printf("Impossible\n");
else
{
int ans=;
for(int i=;i<=n;i++)
{
int temp=(du[i]+)/;
while(temp)
ans=ans^a[i],temp--;
}
if(sum==)
{
int temp=ans;
for(int i=;i<=n;i++)
ans=max(temp^a[i],ans);
}
printf("%d\n",ans);
}
}
}

HDU 5883 欧拉路径异或值最大 水题的更多相关文章

  1. HDU 5832 A water problem(某水题)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  2. hdu 2393:Higher Math(计算几何,水题)

    Higher Math Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. <hdu - 3999> The order of a Tree 水题 之 二叉搜索的数的先序输出

    这里是杭电hdu上的链接:http://acm.hdu.edu.cn/showproblem.php?pid=3999  Problem Description: As we know,the sha ...

  4. HDOJ/HDU 1256 画8(绞下思维~水题)

    Problem Description 谁画8画的好,画的快,今后就发的快,学业发达,事业发达,祝大家发,发,发. Input 输入的第一行为一个整数N,表示后面有N组数据. 每组数据中有一个字符和一 ...

  5. hdu 1164:Eddy's research I(水题,数学题,筛法)

    Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  6. HDU ACM 1073 Online Judge -&gt;字符串水题

    分析:水题. #include<iostream> using namespace std; #define N 5050 char a[N],b[N],tmp[N]; void Read ...

  7. hdu 1754 I Hate It(线段树水题)

    >>点击进入原题测试<< 思路:线段树水题,可以手敲 #include<string> #include<iostream> #include<a ...

  8. HDU 5583 Kingdom of Black and White 水题

    Kingdom of Black and White Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showpr ...

  9. hdu - 1394 Minimum Inversion Number(线段树水题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1394 很基础的线段树. 先查询在更新,如果后面的数比前面的数小肯定会查询到前面已经更新过的值,这时候返回的sum ...

随机推荐

  1. Android如何用阿里云的API进行身份证识别

    准备工作:在libs下添加 alicloud-Android-apigateway-sdk-1.0.1.jar,commons-codec-1.10-1.jar 在build.gradle添加  co ...

  2. COGS 1439. [NOIP2013]货车运输

    ★★☆   输入文件:truck.in   输出文件:truck.out   简单对比时间限制:1 s   内存限制:128 MB [题目描述] [来源] CCF全国信息学奥林匹克联赛(NOIP201 ...

  3. Python3基础教程(十六)—— 迭代器、生成器、装饰器

    在这个实验里我们学习迭代器.生成器.装饰器有关知识. 这几个概念是 Python 中不容易理解透彻的概念,务必把所有的实验代码都完整的输入并理解清楚其中每一行的意思. 迭代器 Python 迭代器(I ...

  4. 初识WEBGL

    WEBGL (全写Web Graphics Library)是一种3D绘图协议,这种绘图技术标准允许把JavaScript和OpenGL ES 2.0结合在一起,通过增加OpenGL ES 2.0的一 ...

  5. IIR数字滤波器

    对于N阶IIR的计算方程式为: 一阶 Y(n)=a∗X(n)+(1−a)∗Y(n−1) 二阶 y[n]=b0⋅x[n]+b1⋅x[n−1]+b2⋅x[n−2]−a1⋅y[n−1]−a2⋅y[n−2]

  6. Mathematics-基础:斐波那契数列

    f(1)=1 f(2)=1 f(n)=f(n-1)+f(n-2) n>2

  7. Java中的枚举--Enumeration

    之前并没有注意到枚举这个知识点,因为之前在项目中并没有使用过枚举,可能是项目并不是很复杂的原因吧,今天看张孝祥老师的讲解,觉得,这个枚举真的有很多值得学习的地方,探究一下枚举的设计原理,底层到底是怎么 ...

  8. 打开VS2015提示“重新启动处于挂起状态。请在启动Visual Studio”之前重新启动

    昨晚安装了VS2015,今天打开VS2015提示[“重新启动处于挂起状态.请在启动Visual Studio”之前重新启动] 这里重新启动指的是重启电脑 解决方法: 电脑需要重启电脑

  9. luogu P3916 图的遍历

    P3916 图的遍历 题目描述 给出 N 个点, M 条边的有向图,对于每个点 v ,求 A(v) 表示从点 v 出发,能到达的编号最大的点. 输入输出格式 输入格式: 第1 行,2 个整数 N,MN ...

  10. (15) openssl签署和自签署证书的多种实现方式

    1.采用自定义配置文件的实现方法 1.1 自建CA 自建CA的机制:1.生成私钥:2.创建证书请求:3.使用私钥对证书请求签名. 由于测试环境,所以自建的CA只能是根CA. 所使用的配置文件如下: [ ...