首页 > 代码库 > [HDOJ5883]The Best Path(欧拉回路,异或)

[HDOJ5883]The Best Path(欧拉回路,异或)

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

 1 #include <bits/stdc++.h> 2 using namespace std; 3 #define fr first 4 #define sc second 5 #define cl clear 6 #define BUG puts("here!!!") 7 #define W(a) while(a--) 8 #define pb(a) push_back(a) 9 #define Rint(a) scanf("%d", &a)10 #define Rll(a) scanf("%I64d", &a)11 #define Rs(a) scanf("%s", a)12 #define Cin(a) cin >> a13 #define FRead() freopen("in", "r", stdin)14 #define FWrite() freopen("out", "w", stdout)15 #define Rep(i, len) for(int i = 0; i < (len); i++)16 #define For(i, a, len) for(int i = (a); i < (len); i++)17 #define Cls(a) memset((a), 0, sizeof(a))18 #define Clr(a, x) memset((a), (x), sizeof(a))19 #define Full(a) memset((a), 0x7f7f7f, sizeof(a))20 #define lrt rt << 121 #define rrt rt << 1 | 122 #define pi 3.1415926535923 #define RT return24 #define lowbit(x) x & (-x)25 #define onecnt(x) __builtin_popcount(x)26 typedef long long LL;27 typedef long double LD;28 typedef unsigned long long ULL;29 typedef pair<int, int> pii;30 typedef pair<string, int> psi;31 typedef pair<LL, LL> pll;32 typedef map<string, int> msi;33 typedef vector<int> vi;34 typedef vector<LL> vl;35 typedef vector<vl> vvl;36 typedef vector<bool> vb;37 38 const int maxn = 100100;39 int n, m;40 int ret, tmp;41 int a[maxn], in[maxn];42 int pre[maxn];43 44 int find(int x) {45     return x == pre[x] ? x : pre[x] = find(pre[x]);46 }47 48 void unite(int x, int y) {49     x = find(x);50     y = find(y);51     if(x != y) pre[x] = y;52 }53 54 signed main() {55     // FRead();56     int T, u, v;57     Rint(T);58     W(T) {59         Cls(in); ret = 0;60         Rint(n); Rint(m);61         For(i, 1, n+1) {62             pre[i] = i;63             Rint(a[i]);64         }65         Rep(i, m) {66             Rint(u); Rint(v);67             in[u]++; in[v]++;68             unite(u, v);69         }70         int flag = 0;71         For(i, 1, n+1) if(in[i] & 1) flag++;72         if(flag > 2 || flag == 1) {73             puts("Impossible");74             continue;75         }76         For(i, 1, n+1) {77             tmp = (in[i] + 1) / 2;78             W(tmp) ret ^= a[i];79         }80         if(flag == 2) {81             printf("%d\n", ret);82             continue;83         }84         tmp = 0;85         For(i, 1, n+1) {86             if(in[i] != 0) {87                 int cur = ret ^ a[i];88                 tmp = max(tmp, cur);89             }90         }91         printf("%d\n", tmp);92     }93     RT 0;94 }

 

[HDOJ5883]The Best Path(欧拉回路,异或)