hdu5883 The Best Path(欧拉路)
比赛第一遍做的时候没有考虑回路要枚举起点的情况导致WA了一发orz
节点 i 的贡献为((du[i] / 2) % 2)* a[i]
欧拉回路的起点贡献多一次,欧拉通路起点和终点也多一次。
代码如下:
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#define CLR(a,b) memset((a),(b),sizeof((a)))
using namespace std; const int N = ;
const int inf = 0x3f3f3f3f;
int n, m;
int a[N];
int du[N]; int main(){
int t, i, j, b, c, f, ans, dd, ma;
scanf("%d", &t);
while(t--){
ans = ;
scanf("%d %d", &n, &m);
f = ;
ma = ;
CLR(du, );
for(i = ; i<= n; ++i)
scanf("%d", &a[i]);
for(i = ; i <= m; ++i){
scanf("%d %d", &b, &c);
du[b]++; du[c]++;
}
dd = ;
for(i = ; i <= n; ++i){
if(du[i]%) dd++;
}
if(dd == || dd==) f = ; // 欧拉路的奇度顶点数为 2 或 0
if(!f){printf("Impossible\n");continue;}
for(i = ; i<= n; ++i){
if(((du[i] + )/) % == )
ans ^= a[i];
}
if(!dd){//欧拉回路时枚举起点
for(i = ; i <= n; ++i){
int t = ans ^a[i];
ma= max(ma, t);
}
ans = ma;
}
printf("%d\n", ans);
}
return ;
}
hdu5883 The Best Path(欧拉路)的更多相关文章
- hdu_5883_The Best Path(欧拉路)
题目链接:hdu_5883_The Best Path 题意: n 个点 m 条无向边的图,找一个欧拉通路/回路使得这个路径所有结点的异或值最大. 题解: 节点 i 的贡献为((du[i] +1/ 2 ...
- HDU 5883 The Best Path (欧拉路或者欧拉回路)
题意: n 个点 m 条无向边的图,找一个欧拉通路/回路使得这个路径所有结点的异或值最大. 析:由欧拉路性质,奇度点数量为0或2.一个节点被进一次出一次,度减2,产生一次贡献,因此节点 i 的贡献为 ...
- PAT 1126 Eulerian Path[欧拉路][比较]
1126 Eulerian Path (25 分) In graph theory, an Eulerian path is a path in a graph which visits every ...
- The Best Path(HDU5883)[欧拉路]2016青岛online
题库链接:http://acm.hdu.edu.cn/showproblem.php?pid=5883 欧拉回路裸题,第一次接触欧拉路的我是真的长见识了^-^ 懂了欧拉路这道题就是没什么问题了,欧拉路 ...
- hihocoder 1181 欧拉路.二
传送门:欧拉路·二 #1181 : 欧拉路·二 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在上一回中小Hi和小Ho控制着主角收集了分散在各个木桥上的道具,这些道具其 ...
- hiho 1182 : 欧拉路·三
1182 : 欧拉路·三 这时题目中给的提示: 小Ho:是这样的,每次转动一个区域不是相当于原来数字去掉最左边一位,并在最后加上1或者0么. 于是我考虑对于"XYYY",它转动之后 ...
- hiho欧拉路·二 --------- Fleury算法求欧拉路径
hiho欧拉路·二 分析: 小Ho:这种简单的谜题就交给我吧! 小Hi:真的没问题么? <10分钟过去> 小Ho:啊啊啊啊啊!搞不定啊!!!骨牌数量一多就乱了. 小Hi:哎,我就知道你会遇 ...
- SGU 101.Domino (欧拉路)
时间限制: 0.5 sec 空间限制: 4096 KB 描述 多米诺骨牌,一种用小的方的木块或其他材料,每个都被一些点在面上标记,这些木块通常被称为骨牌.每个骨牌的面都被一条线分成两个 方形,两边 ...
- Codeforces 789D Weird journey - 欧拉路 - 图论
Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his mot ...
随机推荐
- JS如何将CST格式的日期转换为制定格式String
<html> <body> <script type="text/javascript"> var d = new Date() dateFor ...
- [CF738A]Interview with Oleg(模拟)
题目链接:http://codeforces.com/contest/738/problem/A 题意:把ogo..ogo替换成***. 写的有点飘,还怕FST.不过还好 #include <b ...
- [SAP ABAP开发技术总结]RETURN、STOP、EXIT、CHECK、LEAVE、REJECT
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- mount命令
注:硬件设备由linux系统自动识别,但必须成功挂载后才能使用 mount #查询已挂载 mount -a #依据配置文件/etc/fstab的内容自动挂载 挂载命令格式: mount [-t 文件 ...
- FZU 2214 Knapsack problem(背包问题)
Description 题目描述 Given a set of n items, each with a weight w[i] and a value v[i], determine a way t ...
- C#中实现多继承的方法
有一个类叫老虎,还有一个类叫苍蝇.现在新创一个超级老虎类,一种可以飞的老虎,超级老虎由于同时也继承自苍蝇 namespace Interface { //飞的接口 public interface I ...
- LAMP配置
参考资料: 1. http://www.cnblogs.com/zhuyp1015/p/3561470.html ↂ Apache服务器: 安装Apache: sudo apt-get install ...
- GIMP学习笔记
参考文献: ① http://www.gimp.org/docs/userfaq.html GIMP是GNU Image Manipulation Program的缩写,sired by Spence ...
- Bootstrap日期和时间表单组件运用兼容ie8
准备动作先到下载Bootstrap日期和时间组件. 1:引入bootstrap.min.css,因为bootstrap-datetimepicker里面的很多样式依赖bootstarp的主样式,字体文 ...
- http1.1和http1.0区别
http1.1和服务器建立连接可以获得多个资源 http1.0和服务器建立连接可以获取一个值