标签:ace with mamicode view distrib name details open pac
https://www.luogu.com.cn/problem/P1341
https://blog.csdn.net/qq_37555704/article/details/83347641
#include<bits/stdc++.h> using namespace std; const int maxn=1e4+10; int m,dis[maxn][maxn],ans; char ru[maxn],a[maxn]; void find(int i){ for(int j=1;j<=125;j++) if(dis[i][j]){ dis[i][j]--; dis[j][i]--; find(j); } a[++ans]=i; return ; } int main(){ // freopen("in","r",stdin); ios::sync_with_stdio(0); cin>>m; for(int i=1;i<=m;i++){ string s;cin>>s; dis[s[0]][s[1]]++;dis[s[1]][s[0]]++; ru[s[0]]++;ru[s[1]]++; } int cnt=0,h=0; for(int i=1;i<=125;i++) if(ru[i]&1){ cnt++; if(!h)h=i; } if(!h) for(int i=0;i<=125;i++) if(ru[i]){ h=i; break; } if(cnt&&cnt!=2){ cout<<"No Solution"; return 0; } find(h); if(ans<m+1){//只要搜完以后判断一下,点数是不是相等就行了,因为m组连边,必有m+1个点,前提是不重复 cout<<"No Solution"; return 0; } for(int i=ans;i>=1;i--) cout << a[i]; return 0; }
P1341 无序字母对(Hierholzer算法判断欧拉回路)
标签:ace with mamicode view distrib name details open pac
原文地址:https://www.cnblogs.com/xcfxcf/p/12383416.html