The Best Path---hdu5883(欧拉路径)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5883
题意:n 个点 m 条无向边的图,找一个欧拉通路/回路使得这个路径所有结点的异或值最大。
先判断是否含有欧拉路径,如果存在的话有两种情况,有起点和终点不同的欧拉路径,这样我们只需把经过奇数次的点的权值异或起来即可;
还有就是起点和终点相同的欧拉回路;我们在原来的基础上枚举出一个起点,使得结果最大即可;
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<set>
using namespace std;
#define met(a, b) memset(a, b, sizeof(a))
#define N 100005
#define INF 0x3f3f3f3f
typedef long long LL; int du[N], n, a[N]; int Judge()
{
int odd = , ans = ;
for(int i=; i<=n; i++)
{
if(du[i]&)
odd++;
} if(odd != && odd != )///度数为奇数的点只有是这两种情况下才存在欧拉路径;
return -; for(int i=; i<=n; i++)
{
du[i] = (du[i]+)/;///经过一个点的次数;
if(du[i]&)///当经过偶数次时异或结果为0,所以只需异或奇数即可;
ans ^= a[i];
}
if(odd == )///当度数都为偶数时,说明存在欧拉回路,我们只需枚举起点,保存最大值即可;
{
for(int i=; i<=n; i++)
ans = max(ans, ans^a[i]);
}
return ans;
} int main()
{
int T, m;
scanf("%d", &T);
while(T--)
{
met(du, ); scanf("%d %d", &n, &m); for(int i=; i<=n; i++)
scanf("%d", &a[i]); for(int i=; i<=m; i++)
{
int u, v;
scanf("%d %d", &u, &v);
du[u] ++; du[v] ++;
} int ans = Judge(); if(ans == -) puts("Impossible");
else printf("%d\n", ans);
}
return ;
}
The Best Path---hdu5883(欧拉路径)的更多相关文章
- The Best Path(HDU5883)[欧拉路]2016青岛online
题库链接:http://acm.hdu.edu.cn/showproblem.php?pid=5883 欧拉回路裸题,第一次接触欧拉路的我是真的长见识了^-^ 懂了欧拉路这道题就是没什么问题了,欧拉路 ...
- hdu5883 The Best Path(欧拉路)
题目链接:hdu5883 The Best Path 比赛第一遍做的时候没有考虑回路要枚举起点的情况导致WA了一发orz 节点 i 的贡献为((du[i] / 2) % 2)* a[i] 欧拉回路的起 ...
- The Best Path HDU - 5883(欧拉回路 && 欧拉路径)
The Best Path Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
- 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) To ...
- HDU5883 The Best Path(欧拉回路 | 通路下求XOR的最大值)
本文链接:http://www.cnblogs.com/Ash-ly/p/5932748.html 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=588 ...
- hiho欧拉路·二 --------- Fleury算法求欧拉路径
hiho欧拉路·二 分析: 小Ho:这种简单的谜题就交给我吧! 小Hi:真的没问题么? <10分钟过去> 小Ho:啊啊啊啊啊!搞不定啊!!!骨牌数量一多就乱了. 小Hi:哎,我就知道你会遇 ...
- poj2337 欧拉路径
poj2337 这道题昨天晚上开始做,今天才A.但是问题想透了, 发现其实没那么难 题目大意: 给你一些单词,如果一个单词的末尾字符与另一个单词首字符相同,则两个的单词可以连接.问是否可以把所有单词连 ...
- PAT甲级 1126. Eulerian Path (25)
1126. Eulerian Path (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue In grap ...
- 【刷题】HDU 5883 The Best Path
Problem Description Alice is planning her travel route in a beautiful valley. In this valley, there ...
- PAT 1126 Eulerian Path[欧拉路][比较]
1126 Eulerian Path (25 分) In graph theory, an Eulerian path is a path in a graph which visits every ...
随机推荐
- Noi2011 : 智能车比赛
假设S在T左边,那么只能往右或者上下走 f[i]表示S到i点的最短路 f[i]=min(f[j]+dis(i,j)(i能看到j)) 判断i能看到j就维护一个上凸壳和一个下凸壳 时间复杂度$O(n^2) ...
- Android 第三方
把优酷.土豆等取出它们真是的视频播放地址:http://vparser.com/ volley 项目地址 https://github.com/smanikandan14/Volley-demo (1 ...
- [leetCode][012] Two Sum (1)
[题目]: Given an array of integers, find two numbers such that they add up to a specific target number ...
- Palindrome Partitioning II Leetcode java
题目: Given a string s, partition s such that every substring of the partition is a palindrome. Return ...
- 【wikioi】1022 覆盖(匈牙利)
http://www.wikioi.com/problem/1022/ 好不容易来一次1A,,水题啊.. 染色后裸匈牙利orz #include <cstdio> #include < ...
- version `GLIBC_2.17' not found
@ 今天把一个linux程序布到线上服务器上时,运行不起来,下面是解决思路. @ 运行程序,报以下错误 root@iZ25uck2l28Z:/tmp/tmp# ./speed_test ./speed ...
- SQL Server 中 with tmp 临时表的用法
SQL Server 中 with tmp 临时表的用法 ----------with临时表用法,有时候采用临时表比采用in的效率更高,避免了全表扫描. 实例中实现了查询普通题.大题.子题目的sql ...
- tomcat6.0安装
tomcat的安装基本是一步一步按提示来就行了: 这里填写用户名和密码,自己一定要记住啊,下面是路径的选择 然后查看安装成功与否,打开浏览器输入 然后看到下面页面就可以了
- IOS第六天(3:scrollView 图片轮播器)
IOS第六天(3:scrollView 图片轮播器) #import "HMViewController.h" #define kImageCount 5 @interface H ...
- 【iCore2 双核心板视频教程一】iM_LAN 100M 以太网模块UDP例程(包含视频教程)
============================== 技术论坛:http://www.eeschool.org 博客地址:http://xiaomagee.cnblogs.com 官方网店:h ...