The Best Path

Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 2401    Accepted Submission(s): 945

Problem Description
Alice is planning her travel route in a beautiful valley. In this valley, there are N lakes, and M rivers linking these lakes. Alice wants to start her trip from one lake, and enjoys the landscape by boat. That means she need to set up a path which go through every river exactly once. In addition, Alice has a specific number (a1,a2,...,an) for each lake. If the path she finds is P0→P1→...→Pt, the lucky number of this trip would be aP0XORaP1XOR...XORaPt. She want to make this number as large as possible. Can you help her?
 
Input
The first line of input contains an integer t, the number of test cases. t test cases follow.

For each test case, in the first line there are two positive integers N (N≤100000) and M (M≤500000), as described above. The i-th line of the next Nlines contains an integer ai(∀i,0≤ai≤10000) representing the number of the i-th lake.

The i-th line of the next M lines contains two integers ui and vi representing the i-th river between the ui-th lake and vi-th lake. It is possible that ui=vi.

 
Output
For 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
 
就是给出点和路 并且每个点上都有一个权值  要求走过所有的路 使得最后权值的异或和最大
 
题解:
  走过每一条路 明显为欧拉路问题
  欧拉路分为两种 1、欧拉回路 2、欧拉路径 
  即源点和汇点相同  和  源点和汇点不同
  在输入的时候去统计每一个点的度数 当每个点的度数都为偶数的时候为欧拉回路(一个入度 对应 一个出度), 当存在两个点的度数为奇数的时候为欧拉路径(源点有奇数个出度  汇点有奇数个入度)
  其他情况 impossible
  对于异或 同假异真 所以若某个点经过偶数次 则可以直接不计 只记奇数次的
  经过某个点的次数 即为 (度数+1)/2  所以遍历每个点的度数 算即可
  但这样算出来的是 源点和汇点不同的情况的
   如图从1到3 1和3的度数均为1 所以1和3经过(1+1)/2次  2的度数为2 所以为(2+1)/2 次
 
那么源点和汇点相同的怎么算呢
  如图 我们设以1为源点 我们只需要枚举源点 再异或一次 即可 如图 虽然1和3之间比上图多了一条边 但是算出来的经过的次数依然和上图的一样1和3是1次  2也是1次  但从1出发最后又回到1了 所以1 经过了两次 所以枚举源点即可
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff;
int w[maxn], drgee[maxn];
int n, m;
int solve()
{
int cnt = ;
rap(i, , n)
if(drgee[i] & )
cnt++;
if(cnt != && cnt != )
return -;
int res = ;
rap(i, , n)
{
drgee[i] = (drgee[i] + ) >> ;
if(drgee[i] & )
res ^= w[i];
}
int tmp = ;
if(cnt == )
{
rap(i, , n)
{
tmp = max(tmp, res^w[i]);
}
res = tmp;
}
return res;
} int main()
{
int T;
rd(T);
while(T--)
{
mem(drgee, );
rd(n); rd(m);
rap(i, , n)
rd(w[i]);
rep(i, , m)
{
int u, v;
rd(u); rd(v);
drgee[u]++;
drgee[v]++;
} int res = solve();
if(res == -)
{
printf("Impossible\n");
continue;
}
else
{
printf("%d\n", res); } } return ;
}
 

The Best Path HDU - 5883(欧拉回路 && 欧拉路径)的更多相关文章

  1. The Best Path HDU - 5883 欧拉通路

    图(无向图或有向图)中恰好通过所有边一次且经过所有顶点的的通路成为欧拉通路,图中恰好通过所有边一次且经过所有顶点的回路称为欧拉回路,具有欧拉回路的图称为欧拉图,具有欧拉通路而无欧拉回路的图称为半欧拉图 ...

  2. HDU 5883 欧拉回路

    题面: 思路: 这里面有坑啊啊啊-.. 先普及一下姿势: 判断无向图欧拉路的方法: 图连通,只有两个顶点是奇数度,其余都是偶数度的. 判断无向图欧拉回路的方法: 图连通,所有顶点都是偶数度. 重点:图 ...

  3. HDU 5883 F - The Best Path 欧拉通路 & 欧拉回路

    给定一个图,要求选一个点作为起点,然后经过每条边一次,然后把访问过的点异或起来(访问一次就异或一次),然后求最大值. 首先为什么会有最大值这样的分类?就是因为你开始点选择不同,欧拉回路的结果不同,因为 ...

  4. HDU 5883 The Best Path (欧拉路或者欧拉回路)

    题意: n 个点 m 条无向边的图,找一个欧拉通路/回路使得这个路径所有结点的异或值最大. 析:由欧拉路性质,奇度点数量为0或2.一个节点被进一次出一次,度减2,产生一次贡献,因此节点 i 的贡献为 ...

  5. 【刷题】HDU 5883 The Best Path

    Problem Description Alice is planning her travel route in a beautiful valley. In this valley, there ...

  6. HDU 5883 欧拉路径异或值最大 水题

    The Best Path Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tot ...

  7. HDU 5883 The Best Path

    The Best Path Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tot ...

  8. hdu 1116 欧拉回路+并查集

    http://acm.hdu.edu.cn/showproblem.php?pid=1116 给你一些英文单词,判断所有单词能不能连成一串,类似成语接龙的意思.但是如果有多个重复的单词时,也必须满足这 ...

  9. hdu 6311 欧拉回路

    题意:求一个图(不一定联通)最小额外连接几条边,使得可以一笔画出来 大致做法 1.找出联通块 2.统计每一个连通块里面度数为奇数的点的个数, 有一个性质 一个图能够用一笔画出来,奇数点的个数不超过2个 ...

随机推荐

  1. parewise算法性能优化

    在<接口自动化测试框架-AIM>这篇博客中,提到了parewise算法. 这次对其进行性能优化,共3点. 一. 因为笛卡尔积和两两拆分,是有序的. 就保证了两两拆分后的每列都是相同位置的元 ...

  2. JMeter做http接口压力测试

    测前准备 用JMeter做接口的压测非常方便,在压测之前我们需要考虑这几个方面: 场景设定 场景分单场景和混合场景.针对一个接口做压力测试就是单场景,针对一个流程做压力测试的时候就是混合场景,需要多个 ...

  3. php js css加载合并函数 宋正河整理

    <?php //php js css加载合并函数 宋正河整理 //转载请注明出处 define('COMBINE_JS',true); define('COMBINE_CSS',true);   ...

  4. 工具 | Sublime

    Sublime 前言 妈耶..\(Sublime\)的界面真的是太好看啦哭哭.. 我永远喜欢Sublime! 强推Sublime... 正文 自从暑假用上的Ubontu 一开始用的是\(gedit\) ...

  5. shutil模块详解

    python常用模块目录 注意:shutil经常遇到路径需要转义一下才能执行,在字符串前面加 r转义  r" " 1.shutil常用方法 import shutil# 删除目录 ...

  6. users命令详解

    基础命令学习目录 原文链接:https://blog.csdn.net/m0_38132420/article/details/78861464 users命令用于显示当前登录系统所有的用户的用户列表 ...

  7. jenkins展示report测试报告的配置

    HTML报告展示 1. 需要HTML Publisher plugin插件 2. 在workspace下的工程(构建)中的目录中存储测试报告 在Jenkins中新建一个job,进入配置项. 首先通过p ...

  8. 部署Maven项目到tomcat报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener【转】

    部署Maven项目到tomcat报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderLi ...

  9. 以符合人类阅读的方式打印php数组【转载】

    在程序开发过程中:打印数据进行查看调试是非常频繁的:如果没有一种易于阅读的样式那是相当痛苦的: 先定义一个数组: 1 2 3 4 5 6 7 8 9 $array=array(     't0'=&g ...

  10. JS进阶系列之原型、原型链

    最近在看 JavaScript忍者秘籍 这本书的时候,再加上最近遇到的关于原型.原型链的面试题,所以萌生了要把这些知识梳理一遍的想法,所以以下是我自己对原型.原型链的看法 什么是原型 提到原型,我们可 ...