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. linux系统中上传文件与下载文件的方式

    方式一:FileZilla 使用FileZilla第三方工具 绿色版直接打开exe文件即可 主机:连接的linux服务器的IP地址 用户名:登录的用户名 密码:登录密码 端口:默认使用22 左边是自己 ...

  2. 学习java的第二十三天

    一.今日收获 1.java完全学习手册第三章算法的3.2排序,比较了跟c语言排序上的不同 2.观看哔哩哔哩上的教学视频 二.今日问题 1.快速排序法的运行调试多次 2.哔哩哔哩教学视频的一些术语不太理 ...

  3. spring boot 之监听器ApplicationListener

    监听器ApplicationListener 就是spring的监听器,能够用来监听事件,典型的观察者模式.ApplicationListener和ContextRefreshedEvent一般都是成 ...

  4. Java SSLSocket

    Java SSLSocket JSSE(Java Security Socket Extension)是Sun公司为了解决互联网信息安全传输提出的一个解决方案,它实现了SSL和TSL协议,包含了数据加 ...

  5. Mysql百万级数据索引重新排序

    参考https://blog.csdn.net/pengshuai007/article/details/86021689中思路解决自增id重排 方式一 alter table `table_name ...

  6. 【编程思想】【设计模式】【结构模式Structural】front_controller

    Python版 https://github.com/faif/python-patterns/blob/master/structural/front_controller.py #!/usr/bi ...

  7. 【spring AOP】@Pointcut的12种用法

    @Pointcut用来标注在方法上来定义切入点. 使用格式:@ 注解(value="表达标签 (表达式格式)").如:@Pointcut("execution(* com ...

  8. 莫烦python教程学习笔记——保存模型、加载模型的两种方法

    # View more python tutorials on my Youtube and Youku channel!!! # Youtube video tutorial: https://ww ...

  9. Linux中的正则

    目录 一.匹配规则 二.举例 一.匹配规则 * 匹配 0 或多个字符 ? 匹配任意一个字符 [list] 匹配 list 中的任意单一字符 [^list] 匹配 除list 中的任意单一字符以外的字符 ...

  10. 如何利用火焰图定位 Java 的 CPU 性能问题

     常见 CPU 性能问题 你所负责的服务(下称:服务)是否遇到过以下现象: 休息的时候,手机突然收到大量告警短信,提示服务的 99.9 line 从 20ms 飙升至 10s: 正在敲代码实现业务功能 ...