UVA 10054 The Necklace (Oraton Road)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.