Title: Oralu and Euler circuits
Describe:
To a graph, if there is Euler loop from the first point as the starting point for the traversal, if there is a Euclidean road, the dictionary is a large starting point to start the traversal, in the process of traversal, the dictionary sequence of small first traversal, there is no output-1. Note that there may be multiple edges between two points, please traverse all, and there may be self-loops.
"Input Format"
The first line n,e is the number of points and sides, and the next e-line has two numbers per row, indicating that there is a non-forward edge between them.
"Output Format"
A number of numbers representing the traversal order.
"Sample Input"
3 2
1 2
2 3
"Sample Output"
3 2 1
Prompted
N<=20 e<=500
Analysis: Recently just learned Euler road algorithm, so brush a wave of problems. The name of the problem looks very good, the algorithm is also very fruit. It's just a separate sentence for which path to take. Note the vertex-marking discontinuous problem, often by the pit, seems to have become an important pit (Biao) point (zhi) of this type of problem. The code is a bit long.
AC Code:
ProgramZht;varN,M,I,P,MAX,TN,X,Y,S:LONGINT;D,BH:Array[0.. -] ofLongint;a:Array[0.. -] ofLONGINT;MAP1,MAP2:Array[0.. -,0.. -] ofLongint;procedureDFS1 (x:longint);varI:longint;begin fori:=1 toN Do ifMap1[x,i]>0 Then beginDec (map1[x,i]); Dec (map1[i,x]); DFS1 (i) ;End; Inc (TN); A[TN]:=x;End;procedureDFS2 (x:longint);varI:longint;begin fori:=1 toN Do ifMap2[x,i]>0 Then beginDec (map2[x,i]); Dec (map2[i,x]); DFS2 (i) ;End; Inc (TN); A[TN]:=x;End;procedureChuli1;varK:longint;beginK:=0;d FS1 (1); forK:=tnDownto 1 Dowrite (A[k],' ');End;procedureChuli2;varK:longint;beginK:=0;d FS2 (max); forK:=tnDownto 1 DoInc (Bh[a[k]); forK:=tnDownto 1 Dowrite (A[k],' ');End;beginassign (input,'path_euler.in'); Assign (output,'Path_euler.out'); reset (input); rewrite (output); Readln (n,m) ; fori:=1 toM Dobeginreadln (x, y); Inc (Map1[x,y]); Inc (Map1[y,x] ); Inc (Map2[x,y]); Inc (Map2[y,x]); Inc (D[x]); Inc (D[y]);End; fori:=1 toN Doif(d[i]=0)or(D[i]MoD 2=1) Then beginp:=1; BreakEnd; fori:=1 toN DoifD[i]MoD 2=1 Then begin ifI>max Thenmax:=I; Inc (s);End;if(s<>2) and(p=1) Then beginWriteln ('-1'); ExitEnd;ifp=0 ThenChuli1Elsechuli2;close (input); close (output);End.View Code
Euler circuit--Oralu and Euler circuit