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 ...
随机推荐
- IE6/7/8兼容问题、时间对象返回NAN
IE浏览器不支持new Date()带"2,31,2013"这样格式的参数,要换成“2/31/2013”.'2013-05-05'.replace(/-/g,'/')
- [leetCode][003] Intersection of Two Linked Lists
[题目]: Write a program to find the node at which the intersection of two singly linked lists begins. ...
- [leetCode][012] Two Sum (1)
[题目]: Given an array of integers, find two numbers such that they add up to a specific target number ...
- 【BZOJ】1503: [NOI2004]郁闷的出纳员(Splay)
http://www.lydsy.com/JudgeOnline/problem.php?id=1503 这题没有看题解就1a了-好开心,, 其实后面去看题解发现他们的都很麻烦,其实有种很简单的做法: ...
- shell条件与循环
一.if语句 if [expression] then elif[expression] then else fi 注 : expression前后要有空格:判断相等用 = 而不是 == : then ...
- CSS3选择器(三)之伪类选择器
伪类选择器对于大家来说最熟悉的莫过于:link,:focus,:hover之类的了,因为这些在平时中是常用到的伪类选择器,那么先和大家一起简单总 结一下CSS中常用的伪类选择器的使用方法,最后把重心放 ...
- MUI - 预加载
预加载都是在mui.init({)}中执行的 方式一:preload一次仅能预加载一个页面(除非循环) var subWebview = mui.preload({ url: 'examples/ac ...
- System-Defined Device Setup Classes Available to Vendors
https://msdn.microsoft.com/en-us/library/windows/hardware/ff553426(v=vs.85).aspx
- 【新产品发布】iM_VGA 真彩显示VGA模块!(含视频教程)
============================== 技术论坛:http://www.eeschool.org 博客地址:http://xiaomagee.cnblogs.com 官方网店:h ...
- POJ 2528 Mayor's posters(线段树区间染色+离散化或倒序更新)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 59239 Accepted: 17157 ...