日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【HDU - 5883】The Best Path(判断欧拉回路)

發布時間:2023/12/10 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 5883】The Best Path(判断欧拉回路) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

Alice is planning her travel route in a beautiful valley. In this valley, there are?NN?lakes, and?MM?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,...,ana1,a2,...,an) for each lake. If the path she finds is?P0→P1→...→PtP0→P1→...→Pt, the lucky number of this trip would be?aP0XORaP1XOR...XORaPtaP0XORaP1XOR...XORaPt. She want to make this number as large as possible. Can you help her?

Input

The first line of input contains an integer?tt, the number of test cases.?tt?test cases follow.?

For each test case, in the first line there are two positive integers?N?(N≤100000)N?(N≤100000)?and?M?(M≤500000)M?(M≤500000), as described above. The?ii-th line of the next?NN?lines contains an integer?ai(?i,0≤ai≤10000)ai(?i,0≤ai≤10000)?representing the number of the?ii-th lake.?

The?ii-th line of the next?MM?lines contains two integers?uiui?and?vivi?representing the?ii-th river between the?uiui-th lake and?vivi-th lake. It is possible that?ui=viui=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

題目大意:

一個圖,每一條邊必須且只能經過一次,寫出經過點的路徑,類似于p1->p2->p1,求一條路徑,使得路徑的點的異或和最大,求這個最大值。

解題報告:

首先判斷聯通,然后看是否有歐拉回路或者歐拉通路,然后兩種情況分別判斷。如果都沒有則輸出impossible。

AC代碼:

#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<vector> #include<cctype> using namespace std; typedef long long ll; const int maxn=1e5+10; int n,m,in[maxn]; int a[maxn]; vector<int> vv[maxn]; int main() {int t,i,j,k,cnt,u,v,ans=0;int sum=0;cin>>t; while(t--){scanf("%d%d",&n,&m);cnt=0;for(i=1;i<=n;i++){scanf("%d",&a[i]);in[i]=0;vv[i].clear();}for(i=1;i<=m;i++){scanf("%d%d",&u,&v);vv[u].push_back(v);vv[v].push_back(u);in[u]++; in[v]++;}for(i=1;i<=n;i++){// cout<<i<<":"<<in[i]<<endl;cnt+=(in[i]&1);}if(cnt==1||cnt>2){puts("Impossible");continue;}ans=0;if(cnt){for(i=1;i<=n;i++){if(in[i]&1){ans^=a[i];if(((in[i]-1)/2)%2)ans^=a[i];}else if((in[i]/2)%2)ans^=a[i];}}else {sum=0;for(i=1;i<=n;i++){if((in[i]/2)%2)sum^=a[i];}for(i=1;i<=n;i++)ans=max(ans,sum^a[i]);}printf("%d\n",ans);}return 0; }

?

總結

以上是生活随笔為你收集整理的【HDU - 5883】The Best Path(判断欧拉回路)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。