HDU 5883 The Best Path(欧拉路径\回路)
来源:互联网 发布:数据库自然连接语句 编辑:程序博客网 时间:2024/05/29 11:20
代码:
#include <map>#include <set>#include <stack>#include <queue>#include <cmath>#include <string>#include <vector>#include <cstdio>#include <cctype>#include <cstring>#include <sstream>#include <cstdlib>#include <iostream>#include <algorithm>#pragma comment(linker,"/STACK:102400000,102400000")using namespace std;#define MAX 100005#define MAXN 1000005#define maxnode 15#define sigma_size 30#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define lrt rt<<1#define rrt rt<<1|1#define middle int m=(r+l)>>1#define LL long long#define ull unsigned long long#define mem(x,v) memset(x,v,sizeof(x))#define lowbit(x) (x&-x)#define pii pair<int,int>#define bits(a) __builtin_popcount(a)#define mk make_pair#define limit 10000//const int prime = 999983;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f;const double pi = acos(-1.0);const double inf = 1e18;const double eps = 1e-4;const LL mod = 1e9+7;const ull mx = 133333331;/*****************************************************/inline void RI(int &x) { char c; while((c=getchar())<'0' || c>'9'); x=c-'0'; while((c=getchar())>='0' && c<='9') x=(x<<3)+(x<<1)+c-'0'; }/*****************************************************/int a[MAX];int degree[MAX];int pre[MAX];int ret[MAX];int Find(int x){ return pre[x]==x?x:pre[x]=Find(pre[x]);}int main(){ //freopen("in.txt","r",stdin); int t; cin>>t; while(t--){ int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++){ pre[i]=i; } mem(degree,0);mem(ret,0); for(int i=0;i<m;i++){ int x,y; scanf("%d%d",&x,&y); degree[x]++; degree[y]++; int xx=Find(x); int yy=Find(y); if(xx!=yy) pre[xx]=yy; } if(m==0){ int maxn=0; for(int i=1;i<=n;i++){ maxn=max(maxn,a[i]); } cout<<maxn<<endl; continue; } for(int i=1;i<=n;i++){ if(degree[i]){ ret[Find(i)]=1; } } int num=0; for(int i=1;i<=n;i++){ if(ret[i]) num++; } if(num>1){ printf("Impossible\n"); continue; } num=0; for(int i=1;i<=n;i++){ if(degree[i]%2) num++; } if(num==2){ int ans=0; for(int i=1;i<=n;i++){ if(degree[i]){ int k=(degree[i]+1)/2; if(k%2) ans^=a[i]; } } cout<<ans<<endl; } else if(num==0){ int ans=0; for(int i=1;i<=n;i++){ if(degree[i]){ int k=degree[i]/2; if(k%2) ans^=a[i]; } } int maxn=0; for(int i=1;i<=n;i++){ if(degree[i]){ maxn=max(maxn,ans^a[i]); } } cout<<maxn<<endl; } else printf("Impossible\n"); } return 0;}
0 0
- HDU 5883 The Best Path(欧拉路径\回路)
- hdu 5883 The Best Path 欧拉路径(回路)
- hdu 5883 The Best Path 欧拉回路(路径)
- HDU 5883 The Best Path 欧拉路径/回路
- hdu 5883 The Best Path 欧拉路径 & 欧拉回路 并查集
- HDU 5883 The Best Path(欧拉道路+回路)
- the best path(欧拉回路,欧拉路径)
- HDU 5880 The Best Path 欧拉回路+异或 *
- hdu 5883 The Best Path【欧拉路经/欧拉回路】
- HDU-5883 The Best Path(欧拉通路和欧拉回路)
- HDU 5883 The Best Path(欧拉通路与欧拉回路)
- hdu5883 The Best Path(欧拉通路、欧拉回路)
- HDU5883 The Best Path(欧拉回路)
- The Best Path 并查集 + 欧拉回路
- HDU 5883 The Best Path (枚举 欧拉通路)
- hdoj5883The Best Path【欧拉回路】
- HDU 5883 The Best Path(并查集+欧拉回路 or 欧拉路)——2016 ACM/ICPC Asia Regional Qingdao Online
- hdu5883The Best Path(欧拉通路&&欧拉回路)
- linux下升级gblic
- JavaScript版几种常见排序算法
- Android Laucher3 去掉二级菜单
- win7创建wifi给手机
- 【iOS_Development】广告图的添加
- HDU 5883 The Best Path(欧拉路径\回路)
- 牛顿法
- CVPR 2016-9-19
- Html5页面开发app之查询按钮悬浮窗
- Android 数据持久化技术(即数据存储方式)
- How to optimize the WebStrom performance?
- 在苹果iOS平台中获取当前程序进程的进程名等信息
- $(document).ready()加载顺序和事件
- jdbc连接数据库出现的问题,Statement一直为null