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虚拟机电池状态设置

    问题描述: 安装SDK后使用AVD配合APPIUM进行测试,此时虚拟机的电池状态为0%充电中:部分APP会对手机电池状态有要求,不符合要求时,无法安装或打开. 解决思路: 1.Android系统设置( ...

  2. Hive工具类

    Hive2.x的工具类,对常用方法进行了封装,其中设置了kerberos认证. package com.ideal.template.openbigdata.util; import java.sql ...

  3. springBoot + KISSO实现单点登录

    1:创建一个maven项目 kisso,然后再创建二个子项目都是springboot 2:二个boot项目的pom.xml都是一样的 就这三个依赖,3:接下来就是码代码了,首先在(在我这里)sprin ...

  4. docker的安装及基础操作与镜像构建

    仓库配置及安装启动 [root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2 [root@loca ...

  5. vue与node和npm关系

    (1)node功能 准确的说是使用vue-cli 脚手架搭建项目的时候需要nodejs.也可以用script标签引入vue.min.js这样的,在js里实例化vue也行. 使用node有几件事,打包部 ...

  6. VC-基础:常用的安全CRT函数

    常用的安全CRT函数 安全CRT(C Runtime Library = C运行时间库)函数,是微软公司对C/C++语言的扩展.它在原来函数名后添加了“_s”后缀:一般返回出错代码:并将原来的函数返回 ...

  7. C-基础:函数返回局部变量

    一般的来说,函数是可以返回局部变量的. 局部变量的作用域只在函数内部,在函数返回后,局部变量的内存已经释放了.因此,如果函数返回的是局部变量的值,不涉及地址,程序不会出错.但是如果返回的是局部变量的地 ...

  8. java程序中中文没有乱码,存入数据库后中文乱码问题

    jdbc.driver=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/sys_user?useOldAliasMetadataBe ...

  9. springmvc下载那些事

    文件的上传下载一般在项目中还是非常实用的,此处专门整理一下文件的下载,至于文件的上传实现将在后续中补上.文件的下载多用于模板文件的下载,这在项目中用的还是挺多的.今天用到了就整理出来了,以供搬运工们借 ...

  10. Openstack实验笔记

    Openstack实验笔记 制作人:全心全意 Openstack:提供可靠的云部署方案及良好的扩展性 Openstack简单的说就是云操作系统,或者说是云管理平台,自身并不提供云服务,只是提供部署和管 ...