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多个,于是预处理出来,然 ...
随机推荐
- ABAP关键字和ABAP词汇
下表为ABAP的词汇概览(包括关键字): ABAP-SOURCE ABBREVIATED ABS ABSTRACT ACCEPT ACCEPTING ACCORDING ACOS ACTIVATION ...
- luogu P1453 城市环路
题目描述 整个城市可以看做一个N个点,N条边的单圈图(保证图连通),唯一的环便是绕城的环路.保证环上任意两点有且只有2条路径互通.图中的其它部分皆隶属城市郊区. 现在,有一位名叫Jim的同学想在B市开 ...
- vue+element-ui:table表格中的slot 、formatter属性
slot 插槽,table中表示该行内容以自定义方式展示 :formatter 方法,用来格式化内容 Function(row, column, cellValue, index) html < ...
- SQL Server 日志收缩方法
在日常运维中,有时会遇到"The transaction log for database 'xxxx' is full due to 'ACTIVE_TRANSACTION'." ...
- 编译Nacos,解决No Server available 以及 failed to req API__nacos_v1_ns_instance after all servers
问题描述:如图,显示没有服务可用 仔细看控制台,看到上面Error部分,相关参数没有读取到配置信息,那么配置信息这块似乎是有问题,赶紧看看IDE对配置信息的扫描情况: 可以看到有信息了,但是报错:No ...
- linux上jar项目启动脚本
---------------启动:start.sh #!/bin/bashcd `dirname $0`BIN_DIR=`pwd`cd ..DEPLOY_DIR=`pwd`CONF_DIR=$DEP ...
- 这些年来,一直不知道Code Fisrt的真实意义。
目录 Code First 是一个糟糕的名字 放弃 EDMX,但继续实行数据库优先 Code First 是一个糟糕的名字 很多人依据它的名字认为,它是在代码定义模型,然后从模型生成数据库. Code ...
- 【ElasticSearch】 使用AWS云ES服务来分析程序日志
最近公司系统升级,有些API的调用接口达到了每天10几万的请求量.目前公司里的日志,都是写文本文件中的.为了能够更好的分析这些日志数据,公司采用了AWS 的 ElasticSearch服务来分析日志. ...
- Tensorflow-卷积神经网络CNN
卷积神经网络CNN 结构 池化操作 手写数字-卷积神经网络实现 import tensorflow as tf from tensorflow.examples.tutorials.mnist imp ...
- Thinkphp5 由Request导致的RCE漏洞版本小结
一. tp5.0.0-5.0.12 这版本是直接可以利用的,无需captcha模块. 分析:thinkphp/library/think/App.php 中的run方法: filter(方法就是给$r ...