hdu 5883
InputThe first line of input contains an integer tt, the number of test cases. tt test cases follow.
For each test case, in the first line there are two positive integers N (N≤100000)N (N≤100000) and M (M≤500000)M (M≤500000), as described above. The ii-th line of the next NN lines contains an integer ai(∀i,0≤ai≤10000)ai(∀i,0≤ai≤10000) representing the number of the ii-th lake.
The ii-th line of the next MM lines contains two integers uiui and vivi representing the ii-th river between the uiui-th lake and vivi-th lake. It is possible that ui=viui=vi.OutputFor 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
题意:t组数据,n个点,m条边。每个点都有权值。问这个图能不能构成欧拉通路(或回路。如果能,求从起点异或到终点的值中的最大值。
解题思路:判断下能否构成,如果能构成通路,则只有一条路径,如果能构成回路,需要枚举起点。注意异或的时候不需要重现路径,因为
a^a=0所以只要通过某个点偶数次,则这个点就不需要异或。因为在通路中起点和终点的度为奇数,所以取值时应该向上取整。如样例1中
1是起点,度数为1,通过该点的次数也为1,所以应是(nu[i]+1)/2%2才能正确判断通过该点的次数是否为奇数。
而如果是回路,则通过起点的次数要通路多一次,终点的次数不变。(不明白的话可画一个简单的例子模拟一下
所以只需要遍历所有点,取对每个点异或之后的最大值便是答案。
ac代码:
1 #include <cstdio>
2 #include <iostream>
3 #include <cmath>
4 #include <cstring>
5 #include <algorithm>
6 #include <vector>
7 #define ll long long
8 using namespace std;
9 const int maxn = 1e5+10;
10 int nu[maxn];
11 int val[maxn];
12 int main()
13 {
14 int t,n,m;
15 scanf("%d",&t);
16 while(t--)
17 {
18 memset(nu,0,sizeof(nu));
19 scanf("%d%d",&n,&m);
20 for(int i=1;i<=n;++i)
21 {
22 scanf("%d",&val[i]);
23 }
24 int u,v;
25 for(int i=1;i<=m;++i)
26 {
27 scanf("%d%d",&u,&v);
28 nu[u]++;
29 nu[v]++;
30 }
31 int cnt=0;
32 for(int i=1;i<=n;++i)
33 {
34 if(nu[i]%2==1)
35 {
36 cnt++;
37 }
38 }
39 // cout<<cnt<<endl;
40 if(cnt!=0 && cnt!=2)
41 {
42 printf("Impossible\n");
43 continue;
44 }
45 else
46 {
47 int ans=0;
48 for(int i=1;i<=n;++i)
49 {
50 if((nu[i]+1)/2%2==1)
51 ans^=val[i];
52 }
53 if(cnt==0)
54 {
55 int u=ans;
56 for(int i=1;i<=n;++i)
57 {
58 ans=max(ans,u^val[i]);
59 }
60 }
61 printf("%d\n",ans);
62 }
63 }
64 }
hdu 5883的更多相关文章
- HDU 5883 The Best Path
The Best Path Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
- 【刷题】HDU 5883 The Best Path
Problem Description Alice is planning her travel route in a beautiful valley. In this valley, there ...
- The Best Path HDU - 5883(欧拉回路 && 欧拉路径)
The Best Path Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
- HDU 5883 F - The Best Path 欧拉通路 & 欧拉回路
给定一个图,要求选一个点作为起点,然后经过每条边一次,然后把访问过的点异或起来(访问一次就异或一次),然后求最大值. 首先为什么会有最大值这样的分类?就是因为你开始点选择不同,欧拉回路的结果不同,因为 ...
- The Best Path HDU - 5883 欧拉通路
图(无向图或有向图)中恰好通过所有边一次且经过所有顶点的的通路成为欧拉通路,图中恰好通过所有边一次且经过所有顶点的回路称为欧拉回路,具有欧拉回路的图称为欧拉图,具有欧拉通路而无欧拉回路的图称为半欧拉图 ...
- HDU 5883 The Best Path (欧拉路或者欧拉回路)
题意: n 个点 m 条无向边的图,找一个欧拉通路/回路使得这个路径所有结点的异或值最大. 析:由欧拉路性质,奇度点数量为0或2.一个节点被进一次出一次,度减2,产生一次贡献,因此节点 i 的贡献为 ...
- HDU 5883 欧拉路径异或值最大 水题
The Best Path Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
- HDU 5883 欧拉回路
题面: 思路: 这里面有坑啊啊啊-.. 先普及一下姿势: 判断无向图欧拉路的方法: 图连通,只有两个顶点是奇数度,其余都是偶数度的. 判断无向图欧拉回路的方法: 图连通,所有顶点都是偶数度. 重点:图 ...
- 【2016 ACM/ICPC Asia Regional Qingdao Online】
[ HDU 5878 ] I Count Two Three 考虑极端,1e9就是2的30次方,3的17次方,5的12次方,7的10次方. 而且,不超过1e9的乘积不过5000多个,于是预处理出来,然 ...
随机推荐
- [Poi2005]Piggy Banks小猪存钱罐
题目描述 Byteazar有 N 个小猪存钱罐. 每个存钱罐只能用钥匙打开或者砸开. Byteazar已经把每个存钱罐的钥匙放到了某些存钱罐里. Byteazar 现在想买一台汽车于是要把所有的钱都取 ...
- [Usaco2007 Jan]Telephone Lines架设电话线
题目描述 FarmerJohn打算将电话线引到自己的农场,但电信公司并不打算为他提供免费服务.于是,FJ必须为此向电信公司支付一定的费用.FJ的农场周围分布着N(1<=N<=1,000)根 ...
- 渗透测试中期--漏洞复现--MS08_067
靶机:Win2k3 10.10.10.130 攻击机:BT5 10.10.10.128 一:nmap 查看WinK3是否开放端口3389 开放3389方法:我的电脑->属性-&g ...
- JavaScript中eval的替代方法
引自:https://www.cnblogs.com/lxg0/p/7805266.html 通常我们在使用ajax获取到后台返回的json数据时,需要使用 eval 这个方法将json字符串转换成对 ...
- (14)-Python3之--虚拟环境virtualenv
1.安装virtualenv pip install virtualenv 如果是在Linux下需要把virtualenv添加到/usr/bin目录下 # find / -name virtualen ...
- WPF权限控制——【1】界面布局
本来就不怎么喜欢写博客,好不容易申请了博客园的账号,迈出了先前没有跨越的第一步:转眼间几年的时间就过去了,还是空空如也.今天的心境是这样的,发现wpf相关的资料及源码实在不多,就想写下随笔:一方面是自 ...
- 服务端 TCP 连接的 TIME_WAIT 过多问题的分析与解决
https://mp.weixin.qq.com/s/VRQ_12tzy3gRYD091cI7Ew
- HTML 5 学习第二课
元素:<p>+++++++++</P> 全部内容 标签:<P></P> 属性:标签内部的内容 eg:<img src=" "& ...
- SSL与HTTPS协议
1.SSL 1.1 什么是SSL SSL(Secure Sockets Layer 安全套接层),及其继任者传输层安全(Transport Layer Security,TLS)是为网络通信提供安全及 ...
- TcaplusDB常见问题-数据库原理类
gameserver 如何剔除某个无效的 tcaproxy(接入层)节点? TcaplusDB API 在这里对 tcaproxy 异常做了容灾的处理,API 剔除无效的 tcaproxy 进程的方式 ...