HDU 5883 欧拉路径异或值最大 水题
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
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.
解析 先判断图是否只有一个连通块 然后判断是否存在欧拉回路或者路径 欧拉路径每个点经过 (度数+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 欧拉路径异或值最大 水题的更多相关文章
- HDU 5832 A water problem(某水题)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- hdu 2393:Higher Math(计算几何,水题)
Higher Math Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- <hdu - 3999> The order of a Tree 水题 之 二叉搜索的数的先序输出
这里是杭电hdu上的链接:http://acm.hdu.edu.cn/showproblem.php?pid=3999 Problem Description: As we know,the sha ...
- HDOJ/HDU 1256 画8(绞下思维~水题)
Problem Description 谁画8画的好,画的快,今后就发的快,学业发达,事业发达,祝大家发,发,发. Input 输入的第一行为一个整数N,表示后面有N组数据. 每组数据中有一个字符和一 ...
- hdu 1164:Eddy's research I(水题,数学题,筛法)
Eddy's research I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU ACM 1073 Online Judge ->字符串水题
分析:水题. #include<iostream> using namespace std; #define N 5050 char a[N],b[N],tmp[N]; void Read ...
- hdu 1754 I Hate It(线段树水题)
>>点击进入原题测试<< 思路:线段树水题,可以手敲 #include<string> #include<iostream> #include<a ...
- 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 ...
- hdu - 1394 Minimum Inversion Number(线段树水题)
http://acm.hdu.edu.cn/showproblem.php?pid=1394 很基础的线段树. 先查询在更新,如果后面的数比前面的数小肯定会查询到前面已经更新过的值,这时候返回的sum ...
随机推荐
- ios 从相册视频中获取视频截图
//给image添加个分类 +(UIImage *)getImage:(NSURL: *)videoURL { AVURLAsset *asset = [[AVURLAsset alloc] init ...
- DDR SDRAM
DDR SDRAM(Double Data Rate SDRAM)是一种高速CMOS.动态随机访问存储器, 它采用双倍数据速率结构来完成高速操作.应用在高速信号处理系统中, 需要缓存高速.大量的数据的 ...
- Javaweb学习笔记4—Reuest&Response
今天来讲javaweb的第四段学习. Request和Response还是比较重要的 老规矩,首先先用一张思维导图来展现今天的博客内容. ps:我的思维是用的xMind画的,如果你对我的思维导图感兴趣 ...
- 微信小程序开发系列五:微信小程序中如何响应用户输入事件
微信小程序开发系列教程 微信小程序开发系列一:微信小程序的申请和开发环境的搭建 微信小程序开发系列二:微信小程序的视图设计 微信小程序开发系列三:微信小程序的调试方法 微信小程序开发系列四:微信小程序 ...
- 用python+pygame写贪吃蛇小游戏
因为python语法简单好上手,前两天在想能不能用python写个小游戏出来,就上网搜了一下发现了pygame这个写2D游戏的库.了解了两天再参考了一些资料就开始写贪吃蛇这个小游戏. 毕竟最开始的练手 ...
- scroll offset & client总结
oEvent.clientX 是指鼠标到可视区左边框的距离. oEvent.clientY 是指鼠标到可视区上边框的距离. clientWidth 是指可视区的宽度. clientHeight 是 ...
- python基础一 day2 字符串操作
s.capitalize() s.upper() s.lower() s.swapcase() s.title() s.center(20,"#") s.expand ...
- 记一次Linux系统被入侵的过程
记一次Linux系统被入侵的过程 1. 前期现象 前期现象,宋组那边反应开发环境192.161.14.98这台机器通过公网下载文件,很慢,ping百度丢包严重.因为这台机器是通过楼下adsl拨号上网, ...
- github 新建一个仓库后
每次都记不住命令,记一下,防止找不到 echo "# learn18" >> README.md git init git add README.md git comm ...
- Linux网络技术管理
1. OSI七层模型和TCP/IP四层模型 1.1 osi 七层模型 Open System interconnection,开放系统互连参考模型是国际标准化组织(ISO)制定的一个用于计算机或通信系 ...