///////////////////////////////////////////////////////////////////////////////////////////////////////
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