hdu5883 The Best Path 2016-09-21 21:31 92人阅读 评论(0) 收藏
The Best Path
Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 798    Accepted Submission(s): 332
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?
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.
2
3 2
3
4
5
1 2
2 3
4 3
1
2
3
4
1 2
2 3
2 4
2
Impossible
题目的意思是遍历所有边,算出每个经历过的点异或起来最大值
首先并查集算出集合数,大于1不可能;然后判欧拉回路,若度为奇的大于2,则不可能,若度为奇的等于二,则路线固定,其所经历所有点,若等于零则枚举起点
这里有个小技巧,a^a=0,0^a=a 所以异或时重复经历的点只要判经历次数是否为奇数即可
另外有个坑的是位运算优先级较低,你写
for(int i=1; i<=n; i++)
{
if(ans^a[i]>mx)
mx=ans^a[i];
}
就会wa,它先会判断>再异或
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 10000007
#define maxn 100005 int a[maxn];
int p[maxn];
int pre[maxn];
int n,m,sz; int fin(int x)
{
if(x != pre[x])
pre[x] = fin(pre[x]);
return pre[x];
} void unio(int x,int y)
{
int x1=fin(x);
int x2=fin(y);
if(x1!=x2)
{
pre[x1]=x2;
sz--;
}
} int main()
{
int o,u,v;
while(~scanf("%d",&o))
{
while(o--)
{
scanf("%d%d",&n,&m);
for(int i=1; i<=n; i++)
{
scanf("%d",&a[i]);
}
memset(p,0,sizeof(p));
for(int i=1; i<=n; i++)
{
pre[i]=i;
}
sz=n; for(int i=0; i<m; i++)
{
scanf("%d%d",&u,&v);
unio(u,v);
p[u]++;
p[v]++;
} if(sz>1)
{
printf("Impossible\n");
continue;
} int tot=0;
for(int i=1; i<=n; i++)
{
if(p[i]%2==1)
tot++;
}
if(tot>2)
{
printf("Impossible\n");
}
else if(tot==2)
{
int ans=0;
for(int i=1; i<=n; i++)
{
if(((p[i]+1)/2)%2)
ans=ans^a[i];
}
printf("%d\n",ans);
}
else
{
int ans=0;
for(int i=1; i<=n; i++)
{
if(((p[i]+1)/2)%2) ans=ans^a[i];
}
int mx=0;
for(int i=1; i<=n; i++)
{
mx=max(mx,ans^a[i]);
}
printf("%d\n",mx);
}
}
}
return 0;
}
hdu5883 The Best Path 2016-09-21 21:31 92人阅读 评论(0) 收藏的更多相关文章
- GitHub项目协作基本步骤                                                    分类:            C_OHTERS             2013-09-23 21:31    690人阅读    评论(0)    收藏
		
1.查找某个项目,然后Fork 2.打开GitHub For Windows,发现刚才Fork的项目 3.对着项目点击Clone,将之复制至本地 4.使用Eclipse等进行开发,如新增一个文件 5. ...
 - Poj 2349 Arctic Network                                                    分类:            Brush Mode             2014-07-20 09:31    93人阅读    评论(0)    收藏
		
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9557 Accepted: 3187 De ...
 - Poj 1050                                                    分类:            Translation Mode             2014-04-04 09:31    103人阅读    评论(0)    收藏
		
To the Max Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 39058 Accepted: 20629 Desc ...
 - sscanf 函数                                                       分类:            POJ             2015-08-04 09:19    4人阅读    评论(0)    收藏
		
sscanf 其实很强大 分类: 纯C技术 技术笔记 2010-03-05 16:00 12133人阅读 评论(4) 收藏 举报 正则表达式stringbuffercurlgoogle 最近在做日志分 ...
 - python如何使用 os.path.exists()--Learning from stackoverflow                                                    分类:            python             2015-04-23 20:48    139人阅读    评论(0)    收藏
		
Q&A参考连接 Problem:IOError: [Errno 2] No such file or directory. os.path.exists() 如果目录不存在,会返回一个0值. ...
 - 排序练习——找出前m大的数字                                                       分类:            排序             2015-06-08 09:33    21人阅读    评论(0)    收藏
		
排序练习--找出前m大的数字 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 给定n个数字,找出前m大的数字. 输入 多组输 ...
 - windows server 2008 R2域中的DC部署                                                       分类:            AD域             Windows服务             2015-06-06 21:09    68人阅读    评论(0)    收藏
		
整个晚上脑子都有点呆滞,想起申请注册好的博客还从来都不曾打理,上来添添生机.从哪里讲起呢,去年有那么一段时间整个人就陷在域里拔不出来,于是整理了一些文档,害怕自己糊里糊涂的脑子将这些东西会在一觉醒来全 ...
 - Prime Path                                                       分类:            搜索             POJ             2015-08-09 16:21    4人阅读    评论(0)    收藏
		
Prime Path Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14091 Accepted: 7959 Descripti ...
 - Hadoop集群日常运维                                                    分类:            A1_HADOOP             2015-03-01 21:26    502人阅读    评论(0)    收藏
		
(一)备份namenode的元数据 namenode中的元数据非常重要,如丢失或者损坏,则整个系统无法使用.因此应该经常对元数据进行备份,最好是异地备份. 1.将元数据复制到远程站点 (1)以下代码将 ...
 
随机推荐
- 迷你MVVM框架 avalonjs 学习教程14、事件绑定
			
之前的章节许多示例代码也或多或少地展示了如何使用ms-click来绑定事件了.能直接在模板上绑定是事件,这也是静态模板与动态绑定的一大区别.ms-click不是简单的onclick的别名,它在内部屏蔽 ...
 - maven GroupId 和ArtifactId通常填什么
			
GroupID是项目组织唯一的标识符,实际对应JAVA的包的结构,是main目录里java的目录结构.ArtifactID就是项目的唯一的标识符,实际对应项目的名称,就是项目根目录的名称.
 - 3.3 JSP内置对象概述
			
1.request 1.1 request获取页面传来的参数,参数通过浏览器网址和后面添加?的方式传达. 传参:”show.jsp?id=001” 获取参数:request.getParameter( ...
 - 协同过滤 spark scala
			
1 http://www.cnblogs.com/charlesblc/p/6165201.html [转载]协同过滤 & Spark机器学习实战 2 基于Spark构建推荐引擎之一:基于物品 ...
 - mysql备份的三种方式
			
一.备份的目的 做灾难恢复:对损坏的数据进行恢复和还原需求改变:因需求改变而需要把数据还原到改变以前测试:测试新功能是否可用 二.备份需要考虑的问题 可以容忍丢失多长时间的数据:恢复数据要在多长时间内 ...
 - win10关闭后台应用程序进程的方法
			
一)win10系统后台应用有两大特点: 1.win10系统有许多系统自带应用软件,在系统任务栏中看不到任何自带的应用程序运行 2.但通过任务管理器的进程中,可直观的看到许多非系统进程正在运行. 二)后 ...
 - Structs配置文件 zg项目介绍
			
Structs配置文件 1.以系统代码为名称 例:
 - 第五章 二叉树(e1)先序遍历
 - 几种TCP连接终止
			
在三次连接完成后,accept调用前,客户机发来RST. Berkeley实现将完全在内核中处理,不通知. 而SVR4实现将返回一个错误EPROTO,而POSIX指出应该是ECONNABORTED,后 ...
 - 浅谈python中的“ ==” 与“ is”
			
在python中,== 与 is 之间既有区别,又有联系,本文将通过实际代码的演示,力争能够帮助读到这篇文章的朋友以最短的时间理清二者的关系,并深刻理解它们在内存中的实现机制.扯淡的话不多说,下面马上 ...