链接:http://acm.hdu.edu.cn/showproblem.php?pid=5883

解法:先判断是不是欧拉路,然后枚举

#pragma comment(linker, "/STACK:102400000,102400000")
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <iostream>
#include <algorithm>
#define pb push_back
#define fi first
#define se second
#define icc(x) (1<<(x))
#define lcc(x) (1ll<<(x))
#define lowbit(x) (x&-x)
#define debug(x) cout<<#x<<"="<<x<<endl
#define rep(i,s,t) for(int i=s;i<t;++i)
#define per(i,s,t) for(int i=t-1;i>=s;--i)
#define mset(g, x) memset(g, x, sizeof(g))
using namespace std; typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> veci;
const int mod=(int)1e9+7,inf=0x3fffffff,rx[]={-1,0,1,0},ry[]={0,1,0,-1};
const ll INF=1ll<<60;
const db pi=acos(-1),eps=1e-8; template<class T> void rd(T &res){
res = 0; int ch,sign=0;
while( (ch=getchar())!='-' && !(ch>='0'&&ch<='9'));
if(ch == '-') sign = 1; else res = ch-'0';
while((ch=getchar())>='0'&&ch<='9') res = (res<<3)+(res<<1)+ch-'0';
res = sign?-res:res;
}
template<class T>void rec_pt(T x){
if(!x)return;
rec_pt(x/10);
putchar(x%10^48);
}
template<class T>void pt(T x){
if(x<0) putchar('-'),x=-x;
if(!x)putchar('0');
else rec_pt(x);
}
template<class T>inline void ptn(T x){ pt(x),putchar('\n'); }
template<class T>inline void Max(T &a,T b){ if(b>a)a=b; }
template<class T>inline void Min(T &a,T b){ if(b<a)a=b; }
template<class T>inline T mgcd(T b,T d){ return b?mgcd(d%b,b):d; }//gcd模板,传入的参数必须是用一类型
//-------------------------------主代码--------------------------------------// int g[100100];
int d[100100];
int markpath[100100];
int mark[100100]; struct node{
int to,next;
}edge[1000100]; int cnt,pre[100100]; void add_edge(int u,int v){
edge[cnt].to = v;
edge[cnt].next = pre[u];
pre[u] = cnt++;
} void dfs(int s){
mark[s] = 1;
for(int p=pre[s];p!=-1;p=edge[p].next){
int v = edge[p].to;
if(mark[v] == 1) continue;
dfs(v);
}
} int main()
{
int T;
rd(T);
while (T--) {
cnt = 0;
mset(d, 0); mset(markpath, 0); mset(pre, -1); mset(mark, 0);
int n,m;
rd(n),rd(m);
for(int i=1;i<=n;i++)
{
rd(g[i]);
}
rep(i, 0, m){
int x,y;
rd(x),rd(y);
markpath[x] = 1; markpath[y] = 1;
add_edge(x,y);
add_edge(y,x);
d[x]++; d[y]++;
}
int cnt = 0;
for(int i=1;i<=n;i++){
if(d[i]%2 != 0) cnt++;
} if(cnt!=0 && cnt!=2){
printf("Impossible\n");
continue;
}
int flag = 0;
for(int i=1;i<=n;i++){
if(markpath[i]==1 && mark[i] ==0){
flag ++;
dfs(i);
}
}
if(flag > 1) {
printf("Impossible\n");
continue;
} int ans = 0; if(cnt == 0){
int sum = 0;
for(int i=1;i<=n;i++){
if( (d[i]/2)%2!=0 )
{
sum ^= g[i];
}
}
for(int i=1;i<=n;i++){
if(markpath[i]==1)
ans = max(ans,sum^g[i]);
}
}else{
int sum = 0;
for(int i=1;i<=n;i++){
if(d[i]%2!=0){
d[i]++;
}
if( (d[i]/2)%2!=0 )
{
sum ^= g[i];
}
}
ans = sum;
}
ptn(ans);
}
return 0;
}

  

2016 ACM/ICPC Asia Regional Qingdao Online HDU5883的更多相关文章

  1. 2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分

    I Count Two Three Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  2. HDU 5889 Barricade 【BFS+最小割 网络流】(2016 ACM/ICPC Asia Regional Qingdao Online)

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

  3. 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 ...

  4. 【2016 ACM/ICPC Asia Regional Qingdao Online】

    [ HDU 5878 ] I Count Two Three 考虑极端,1e9就是2的30次方,3的17次方,5的12次方,7的10次方. 而且,不超过1e9的乘积不过5000多个,于是预处理出来,然 ...

  5. hdu 5878 I Count Two Three (2016 ACM/ICPC Asia Regional Qingdao Online 1001)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5878 题目大意: 给出一个数n ,求一个数X, X>=n. X 满足一个条件 X= 2^a*3^ ...

  6. Hdu OJ 5884-Sort (2016 ACM/ICPC Asia Regional Qingdao Online)(二分+优化哈夫曼)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5884 题目大意:有n个有序的序列,对于第i个序列有ai个元素. 现在有一个程序每次能够归并k个序列, ...

  7. 2016 ACM/ICPC Asia Regional Qingdao Online HDU5889

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5889 解法:http://blog.csdn.net/u013532224/article/details ...

  8. 2016 ACM/ICPC Asia Regional Qingdao Online HDU5882

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5882 解法:一个点必须出度和入度相同就满足题意,所以加上本身就是判断奇偶性 #include<std ...

  9. 2016 ACM/ICPC Asia Regional Qingdao Online HDU5879

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5879 解法:我们知道到某个极限之后结果相同,所以找到那个极限,其他保存之后输出就好了 #include&l ...

随机推荐

  1. 点的双联通+二分图的判定(poj2942)

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 10804   Acce ...

  2. js eventhandler

    1.获取所有eventhandler 使用 getEventHandler(target) 2.target.addEventHandler(type,handler,userCapture?) 3. ...

  3. interesting js

    [‎5/‎3/‎2016 4:18 PM] Calos Chen: function a(b,e){var a=0;a+=b;if(e){console.log(b+e);return;} retur ...

  4. fzuoj Problem 2182 水题

    http://acm.fzu.edu.cn/problem.php?pid=2182 Problem 2182 水题 Accept: 188    Submit: 277Time Limit: 100 ...

  5. oracle,sqlserver,mysql 命令行 开启、关闭所需要的服务

    ORACLE需要开启的服务   需要启动的服务:   口令: 启动Oracle 11g服务: (下面的可以作为bat 脚本,直接运行便可以不用去自己去启动和关闭服务了.) @echo off @ EC ...

  6. PHP XDEBUG

    PHP调试时,不得不提XDEBUG这个调试利器.学习PHP以来,几乎所有的问题我都利用它来解决. 首先关于如何安装,不在赘述,请自行google之.(需要特别注意的是:PHP5.2 和5.3 ,关于加 ...

  7. Android中使用ShareSDK实现分享

    1,在http://www.mob.com官网上去创建一个后台应用(如果没有账号的同学要去先注册一下),主要后去的是你新创建的应用的appKey值 2,这里我们分享新浪微博为例,在新浪微博的sdk中创 ...

  8. Concurrent Assertion

    Concurrent assertion中要求必须有clock,从而保证在每个clock edge都进行触发判断. assertion与design进行同步执行,concurrent assert只能 ...

  9. test generation和MBIST

    The problem of test generation Random test generation Deterministic algorithm for test generation fo ...

  10. PAT乙级 1008. 数组元素循环右移问题 (20)

    1008. 数组元素循环右移问题 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 一个数组A中存有N(N>0)个整数,在不允 ...