Submitted 7 times, finally AC. The problem is not difficult, is to judge the next Oraton Road. Attention to detail.
/*status:actitle:the necklace*/#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <string> #include <stack> #include <queue> #include <set> #include < Map>typedef Long long ll;using namespace std;const int inf=0x3f3f3f3f;const int maxn=1010;int g[maxn][maxn];int H[MAXN ];//records the number of occurrences of each point bool Vis[maxn];int n,num;void Euler (int u) {for (int v=1;v<=50;v++) if (g[u][v]>0) {G[u][v]--;g[v][u ]--;euler (v);p rintf ("%d%d\n", V,u);}} void Dfs (int u) {num++;vis[u]=true;for (int v=1;v<=50;v++) if (!vis[v] && g[u][v]>0) {dfs (v);}} int main () {int t;scanf ("%d", &t), for (int. cas=1;cas<=t;cas++) {printf ("Case #%d\n", CAs); memset (g,0,sizeof g); memset (h,0,sizeof h); memset (Vis,0,sizeof Vis), while (!s.empty ()) S.pop () Num=0;int first=0;scanf ("%d", &n); int i=0;i<n;i++) {int u,v;scanf ("%d%d", &u,&v), if (first==0) first=u;g[u][v]++;g[v][u]++;h[u]++;h[v]++;} BOOL Ok=true;int cnt=0;for (int i=1;i<=50;i++) {if (h[I]) cnt++;if (h[i]%2!=0) {//If there is a singularity ok=false;break;}} if (!ok) {printf ("Some beads may be lost\n");} Else{dfs (first); if (num==cnt) {Euler (first);} else{printf ("Some beads may be lost\n");}} if (cas<t) printf ("\ n");} return 0;}
UVA 10054 The Necklace (Oraton Road)