The Best Path

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

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 N lines 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 #include<stdio.h>
2 #include<algorithm>
3 #include<string.h>
4 #include<iostream>
5 #include<queue>
6 #include<stdlib.h>
7 #include<math.h>
8 #include<set>
9 using namespace std;
10 int bin[100005];
11 int cnt[100005];
12 int du[100005];
13 int ans[100005];
14 set<int>que;
15 int main(void)
16 {
17 int n;
18 scanf("%d",&n);
19 while(n--)
20 {
21 que.clear();
22 int i,j;
23 memset(cnt,0,sizeof(cnt));
24 for(i = 0; i <= 100005; i++)
25 {
26 bin[i] = i;
27 du[i] = 1;
28 }
29 int N,M;
30 scanf("%d %d",&N,&M);
31 if(M==0)printf("0\n");
32 else
33 {
34 for(i = 1; i <= N; i++)
35 {
36 scanf("%d",&ans[i]);
37 }
38 while(M--)
39 {
40 int x,y;
41 scanf("%d %d",&x,&y);
42 cnt[x]++;
43 cnt[y]++;
44 int xx,yy;
45 for(xx = x; bin[xx]!=xx;)
46 xx = bin[xx];
47 for(yy = y; bin[yy]!=yy;)
48 yy = bin[yy];
49 if(xx != yy)
50 {
51 if(du[xx]>du[yy])
52 {
53 bin[yy] = xx;
54 du[xx] += du[yy];
55 }
56 else
57 {
58 bin[xx] = yy;
59 du[yy] += du[xx];
60 }
61 }
62 }
63 for(i = 1; i <= N; i++)
64 {
65 if(cnt[i])
66 {
67 int xx;
68 for(xx = i; xx!=bin[xx];)
69 xx = bin[xx];
70 que.insert(xx);
71 }
72 }
73 int cn = 0;
74 for(i = 1; i <= N; i++)
75 {
76 if(cnt[i])
77 {
78 if(cnt[i]%2)
79 {
80 cn++;
81 }
82 }
83 }
84 int sum = 0;
85 if(cn == 1|| cn > 3||que.size()!=1)
86 {
87 //printf("1\n");
88 printf("Impossible\n");
89 }
90 else if(cn == 2)
91 {
92 for(i = 1; i <= N; i++)
93 {
94 if(cnt[i]>1)
95 cnt[i]=cnt[i]+1;
96 cnt[i]/=2;
97 if(cnt[i]%2)
98 sum^=ans[i];
99 }
100 printf("%d\n",sum);
101 }
102 else
103 {
104 for(i = 1; i <= N; i++)
105 {
106 if(cnt[i])
107 {
108 sum ^= ans[i];
109 }
110 }
111 int flag = 0;
112 int k = sum;
113 for(i = 1; i <= N; i++)
114 {
115 if(cnt[i])
116 {
117 if(!flag)
118 sum^=ans[i],flag = 1;
119 else sum = max(sum,k^ans[i]);
120 }
121 }
122 printf("%d\n",sum);
123 }
124 }
125 }
126 return 0;
127 }

The Best Path的更多相关文章

  1. NodeJs之Path

    Path模块 NodeJs提供的Path模块,使得我们可以对文件路径进行简单的操作. API var path = require('path'); var path_str = '\\Users\\ ...

  2. 【原】实时渲染中常用的几种Rendering Path

    [原]实时渲染中常用的几种Rendering Path 本文转载请注明出处 —— polobymulberry-博客园 本文为我的图形学大作业的论文部分,介绍了一些Rendering Path,比较简 ...

  3. Node.js:path、url、querystring模块

    Path模块 该模块提供了对文件或目录路径处理的方法,使用require('path')引用. 1.获取文件路径最后部分basename 使用basename(path[,ext])方法来获取路径的最 ...

  4. VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

    1.问题描述 由于安装VS15 Preview 5,搞的系统由重新安装一次:在用vscdoe编译go语言时,出现以下问题: # odbcexec: "gcc": executabl ...

  5. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  6. Leetcode 笔记 112 - Path Sum

    题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...

  7. Thinking in Unity3D:渲染管线中的Rendering Path

      关于<Thinking in Unity3D> 笔者在研究和使用Unity3D的过程中,获得了一些Unity3D方面的信息,同时也感叹Unity3D设计之精妙.不得不说,笔者最近几年的 ...

  8. node之path模块

    node之path模块 原文链接 //引用该模块 var path = require("path"); 1.路径解析,得到规范化的路径格式 对window系统,目录分隔为'', ...

  9. Linux系统修改PATH环境变量方法

    在Linux安装一些软件通常要添加路径环境变量PATH.PATH环境变量通俗的讲就是把程序的路径"备案"到系统中,这样执行这些程序时就不需要输入完整路径,直接在bash输入程序名就 ...

  10. 利用XML FOR PATH 合并分组信息

    -- ================================================ -- Description:合并分组内容 -- Author:夏保华 -- Date:2009 ...

随机推荐

  1. 关于写SpringBoot+Mybatisplus+Shiro项目的经验分享四:部署到阿里云

    框架: SpringBoot+Mybatisplus+Shiro 简单介绍:关于写SpringBoot+Mybatisplus+Shiro项目的经验分享一:简单介绍 阿里云开放必要端口,mysql与t ...

  2. 用原生CSS编写动态字体

    HTML部分: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <t ...

  3. LInkedList总结及部分底层源码分析

    LInkedList总结及部分底层源码分析 1. LinkedList的实现与继承关系 继承:AbstractSequentialList 抽象类 实现:List 接口 实现:Deque 接口 实现: ...

  4. A Child's History of England.37

    Many other noblemen repeating and supporting this when it was once uttered, Stephen and young Planta ...

  5. android 跳到应用市场给软件评分

    1 String packetName = this.getPackageName(); 2 Uri uri = Uri.parse("market://details?id=" ...

  6. 【Linux】【Services】【Package】rpm包制作

    1. 概念 1.1. BUILD:源代码解压之后存放的位置 1.2. RPMS:制作完成之后的RPM包的存放位置,包括架构的子目录,比如x86,x86_64 1.3. SOURCES:所有的原材料都应 ...

  7. Springboot,SSM及SSH的概念、优点、区别及缺点

    Springboot的概念: 是提供的全新框架,使用来简化Spring的初始搭建和开发过程,使用了特定的方式来进行配置,让开发人员不在需要定义样板化的配置.此框架不需要配置xml,依赖于像MAVEN这 ...

  8. Hibernate的基本功能:对数据库的增删改查(创建对象实例)

    一.通过实例化的对象向数据库添加新记录 package com.yh.test; import org.hibernate.Session; import org.hibernate.SessionF ...

  9. .net 5 开发跨平台客户端程序

    介绍下.net 跨平台开发服务端程序的过程, .net 5发布已经有段时间了,.net 5根据微软官方的说法将来只有一个.net版本,也就是不在有core之分.从.net5开始整合.net frame ...

  10. Android: Client-Server communication by JSON

    Refer to: http://osamashabrez.com/client-server-communication-android-json/ This is a sequel to my l ...