日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

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

發布時間:2023/12/10 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【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(判断欧拉回路)的全部內容,希望文章能夠幫你解決所遇到的問題。

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