Uva10054_the neck.pdf

Source: Internet
Author: User

It's easy to find the Euler loop. And output.

Only focus on using stacks to control output.

Why,

If the stack is not used, 1-> 2-> 3-> 1 is returned, and 4-> 5 is output. The connection fails, so if the stack is used, A complete path will be saved.

Because it is an undirected graph, as long as the degree of each point is even, there must be a legal Euler loop.

 

Summon code:

 

 

#include <iostream>#include <cstring>#include <cstdio>using namespace std;int a[51][51],n=50,d[51],m,T;void dfs(int x){    for (int i=1; i<=n; i++)        if (a[x][i])        {            a[x][i]--,a[i][x]--;            dfs(i);            printf("%d %d\n",i,x);        }}int main(){    int cas=0,U,V;    scanf("%d",&T);    while (T--)    {        memset(d,0,sizeof d);        memset(a,0,sizeof a);        scanf("%d",&m);        while (m--)        {            scanf("%d%d",&U,&V);            a[U][V]++,a[V][U]++;            d[U]++,d[V]++;        }        bool ans=true;        for (int i=1; i<=n; i++)            if (d[i]&1) ans=false;        if (cas) printf("\n");        printf("Case #%d\n",++cas);        if (!ans) printf("some beads may be lost\n");            else dfs(U);    }    return 0;}

  

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.