The Best Path

Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)

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的联通块,如果没有,取最大值即可,如果>1个,不可能;
   否则判断是欧拉路还是欧拉回路,欧拉路每个点直接求贡献即可,回路则要取一个使得答案最大的起点,因为起点多算1次;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=1e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t,p[maxn],a[maxn],d[maxn],q[maxn],ans;
int find(int x)
{
return p[x]==x?x:p[x]=find(p[x]);
}
int main()
{
int i,j;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
ans=;
memset(d,,sizeof d);
memset(q,,sizeof q);
rep(i,,n)scanf("%d",&a[i]),p[i]=i;
while(m--)
{
int b,c;
scanf("%d%d",&b,&c);
d[b]++,d[c]++;
int fa=find(b),fb=find(c);
if(fa!=fb)p[fa]=fb;
}
int cnt=;
rep(i,,n)
{
int fa=find(i);
if(p[fa]!=i&&!q[p[fa]])cnt++,q[p[fa]]=;
}
if(cnt>){puts("Impossible");continue;}
else if(cnt==)
{
rep(i,,n)ans=max(ans,a[i]);
printf("%d\n",ans);
continue;
}
cnt=;
rep(i,,n)
{
if(d[i]&)cnt++;
int now=(d[i]+)/;
if(now&)ans^=a[i];
}
if(cnt==)
{
printf("%d\n",ans);
}
else if(cnt==)
{
ans=;
int ma=;
rep(i,,n)
{
int now=(d[i]+)/;
if(now&)ans^=a[i];
}
rep(i,,n)if(d[i])ma=max(ma,ans^a[i]);
printf("%d\n",ma);
}
else puts("Impossible");
}
//system("Pause");
return ;
}

2016青岛网络赛 The Best Path的更多相关文章

  1. HDU 5880 Family View (2016 青岛网络赛 C题,AC自动机)

    题目链接  2016 青岛网络赛  Problem C 题意  给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fa ...

  2. 2016青岛网络赛 Barricade

    Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Proble ...

  3. HDU 5886 Tower Defence(2016青岛网络赛 I题,树的直径 + DP)

    题目链接  2016 Qingdao Online Problem I 题意  在一棵给定的树上删掉一条边,求剩下两棵树的树的直径中较长那的那个长度的期望,答案乘上$n-1$后输出. 先把原来那棵树的 ...

  4. HDU - 5878 2016青岛网络赛 I Count Two Three(打表+二分)

    I Count Two Three 31.1% 1000ms 32768K   I will show you the most popular board game in the Shanghai ...

  5. HDU - 5887 2016青岛网络赛 Herbs Gathering(形似01背包的搜索)

    Herbs Gathering 10.76% 1000ms 32768K   Collecting one's own plants for use as herbal medicines is pe ...

  6. HDU5887 Herbs Gathering(2016青岛网络赛 搜索 剪枝)

    背包问题,由于数据大不容易dp,改为剪枝,先按性价比排序,若剩下的背包空间都以最高性价比选时不会比已找到的最优解更好时则剪枝,即 if(val + (LD)pk[d].val / (LD)pk[d]. ...

  7. HDU5880 Family View(2016青岛网络赛 AC自动机)

    题意:将匹配的串用'*'代替 tips: 1 注意内存的使用,据说g++中指针占8字节,c++4字节,所以用g++交会MLE 2 注意这种例子, 12abcdbcabc 故失败指针要一直往下走,否则会 ...

  8. 2016青岛网络赛 Sort

    Sort Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Des ...

  9. 2016 ACM/ICPC Asia Regional Qingdao Online(2016ACM青岛网络赛部分题解)

    2016 ACM/ICPC Asia Regional Qingdao Online(部分题解) 5878---I Count Two Three http://acm.hdu.edu.cn/show ...

随机推荐

  1. shape的使用

    android在布局边缘位置处理圆角的两个办法: 1),一个是直接让美工切一张带有圆角的图片. 2),使用shape来解决. 第一种不在赘述,主要讲一下第二中方法来实现. 上边缘出现圆角,下边缘正常的 ...

  2. storage size of 'xxx' isn't known问题出现的可能原因之一

    storage size of 'value' isn't known问题出现的可能原因之一 有可能是头文件没有包含起来,所以会出现这种问题可以从以下几个方面来查找原因:1.若是结构体类型,类型是否写 ...

  3. STM32F207 两路ADC连续转换及GPIO模拟I2C给MT9V024初始化参数

    1.为了更好的方便调试,串口必须要有的,主要打印一些信息,当前时钟.转换后的电压值和I2C读出的数据. 2.通过GPIO 模拟I2C对镁光的MT9V024进行参数初始化.之前用我以前公司SP0A19芯 ...

  4. time_t

    所在的头文件为 time.h 定义为: #ifndef __TIME_T #define __TIME_T     /* 避免重复定义 time_t */ typedef long     time_ ...

  5. shell脚本一键同步集群时间

    shell脚本一键同步集群时间 弋嘤捕大 椿澄辄 ψ壤 茇徜燕 ㄢ交涔沔 阚龇棚绍 テ趼蜱棣 灵打了个寒颤也没有去甩脱愣是拖着 喇吉辔 秋北酏崖 琮淄脸酷 茇呶剑 莲夤罱 陕遇骸淫  ...

  6. Asp.Net调用Office组件操作时的DCOM配置 (转)

    Asp.Net调用Office组件操作时的DCOM配置 http://blog.csdn.net/gz775/article/details/6447758 在项目中将数据导出为Excel格式时出现“ ...

  7. 自定义cell,根据数据源,要对cell的布局进行调整,没有实现调整的相应效果

    自定义cell,用于两种显示情况,首次进来A种情况(主材页面),正确显示,然后切换B种情况(辅材情况),可以正确显示,但是当再次切换回A种情况(主材情况)的时候,主材cell不能正常显示了,遗留的B中 ...

  8. 宏定义重写NSLog

    只需要 在ProjectName_Prefix.pch 中追加你对应的宏定义,不用import 就可以直接使用了. #define DEBUG //宏输出函数 #ifdef DEBUG #define ...

  9. js、html中的单引号、双引号及其转义使用

    js.html中的单引号.双引号及其转义使用在js中对相关字符做判断或取值的时候很多情况下都会用到这些. ------ 在一个网页中的按钮,写onclick事件的处理代码,不小心写成如下:<in ...

  10. jquery的校验规则的方法

    //validate 选项*********************************************************** $("form").validat ...