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. iOS应用版本更新(自动提醒用户更新代码)

    在#import "AppDelegate.h" 文件中的application:(UIApplication *)application didFinishLaunchingWi ...

  2. FileZilla Server 端设置passive模式注意事项

    1,需求和问题的产生 实践中需要分布在各地的各个客户端向云端服务器上传文件,因此在阿里云服务器上安装了FileZilla Server软件作为文件FTP服务端. 客户端程序采用FTP方式向服务端传输文 ...

  3. 【HEVC简介】DB-DeBlock Filter

    参考论文:HEVC Deblocking Filter <HEVC标准介绍.HEVC帧间预测论文笔记>系列博客,目录见:http://www.cnblogs.com/DwyaneTalk/ ...

  4. 在DLL中创建窗口时一个值得注意的地方 — UnregisterClass

    背景描述: 今天要测试一份注入代码,拿以前写的创建窗口的DLL来做测试. 第一次注入时一切正常,窗口被成功创建并显示,但在第二次加载时窗口没有显示出来. 经过研究发现在第二次加载DLL时Registe ...

  5. QT 学习笔记概述

    以下笔记为在看书和实践的过程中的部分记录总结: 0. 窗口布局 1) 支持绝对布局和布局管理器布局; 2) 绝对布局不够灵活.无法自动调整大小,需要手动编写代码调整: 3) 布局管理器管理布局比较灵活 ...

  6. docker 搭建 Java Web 运行环境

    安装环境:jdk,tomcat,mysql,nginx

  7. 页面定制CSS代码

    博客皮肤:SimpleMemory .catListTitle { margin-top: 21px; margin-bottom: 10.5px; text-align: left; border- ...

  8. axios token header response request http拦截器 axios实现登录、拦截、登出

    axios token header response request http拦截器 axios实现登录.拦截.登出 一个项目学会前端实现登录拦截 https://github.com/superm ...

  9. 查看cuda版本和cudann

    nvcc -V 没有找到直接查询cudann版本的命令,但发现cudann装在 /usr/local/cuda/lib64/目录下,libcudnn.so就是相应版本

  10. 最小生成树 || HDU 1301 Jungle Roads

    裸的最小生成树 输入很蓝瘦 **并查集 int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } 找到x在并查集里的根结点,如果 ...