2016 ACM/ICPC Asia Regional Qingdao Online HDU5883

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#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;
}

  

 

posted @   樱花落舞  阅读(406)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示