Hiho 50th Week (Euler path) 50

Source: Internet
Author: User

///////////////////////////////////////////////////////////////////////////////////////////////////////
tt267
Disclaimer: This document is subject to the following agreement free reprint-non-commercial-non-derivative-retention Attribution | Creative Commons by-nc-nd 3.0
To view the update and discussion of this article, please click here: http://blog.csdn.net/tt2767/article/details/46493073
///////////////////////////////////////////////////////////////////////////////////////////////////////

Game Link: http://hihocoder.com/contest/hiho50
Title Link: http://hihocoder.com/problemset/problem/1177
(available after the game expires)

The tip of the topic is very clear, is the pseudo-code slightly pits.
Pay attention to the problem of heavy side, WA took me several times

#include <iostream>#include <algorithm>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <sstream>#include <string>#include <iterator>#include <vector>#include <map>#include <stack>#include <queue>#include <set>#include <list>#include <functional>#include <numeric>using namespace STD;typedef  Long Long intLL;Const intINF =99999999;Const Long DoublePI =ACOs(0.0) *2.0;Const intN =1009;//Not too large, memory may overrun Stack<int>SintEdge[n][n];intN,m;BOOLFlag =true;voidFleury (intStart);voidDfsintx);intMain () {intU,v;memset(Edge,0,sizeof(Edge));scanf("%d%d", &n,&m); for(intI=0; i<m; i++) {scanf("%d%d", &u,&v);        edge[u][v]++; edge[v][u]++;//Record the number of edges, there may be heavy edges}intstart=1; for(intI=1; i<=n; i++)//Judging the starting point of the Euler circuit{intDegree=0; for(intj=1; j<=n; J + +) Degree+=edge[i][j];if(degree&1) {start=i; Break;//Take the first one on the go}} fleury (start);return 0;}voidFleury (intu) {s.push (U); while(! S.empty ()) {BOOLBridge =false; for(intI=1; i<=n; i++)//To determine if there is a slip, is to judge the Wood has a bridge{if(Edge[s.top ()][i]>0) {bridge=true; Break; }        }if(bridge) {intV=s.top ();            S.pop (); DFS (v);//If available, on DFS}Else{if(flag)//Make output trailing no spaces{printf("%d", S.top ()); Flag =false; }Else                printf("%d", S.top ());        S.pop (); }    }puts("");}voidDfsintu) {s.push (U); for(intv=1; v<=n; v++) {if(edge[u][v]>0) {edge[u][v]--;//delete this edgeedge[v][u]--; DFS (v); Break; }    }}

Hiho 50th Week (Euler path) 50

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.