Describe
In the last back small hi and small ho control the protagonist gathered scattered on the wooden bridge props, these props are actually a piece of dominoes.
The protagonist continued to move forward, a stone bridge appeared in front of the stone bridge at the end of a fire wall, it seems unable to pass.
Little Hi noticed that there was a small piece of paper at the bridge, so the controlling protagonist picked up the paper, and saw it read:
The flame wall can be closed by placing the M-block dominoes in the concave of the stone bridge. Remember that dominoes need the same number to connect. --by unknown adventurer.
Small hi and Small ho opened the main character of the props bar, found that the protagonist happens to have M fast Domino.
Small ho: That means to put all the dominoes in the groove to close the flame wall, what does the number mean?
Little hi: You see, each piece of dominoes has a number at each end, presumably only when the number is the same, can be placed together, such as:
Little ho: So, let's see if we can connect all the dominoes together.
Input
Line 1th: 2 positive integers, n,m. Indicates the maximum number and number of dominoes that appear on the dominoes, respectively. 1≤n≤1,000,1≤m≤5,000
2nd.. M+1 lines: 2 integers per line, u,v. Line I+1 represents the number (U,V) at both ends of the block I, 1≤u,v≤n
Output
Line 1th: m+1 numbers, indicating the number after the end of a domino
For example, the status of the Domino connection is (1,5) (5,3) (3,2) (2,4) (4,3), then output "1 5 3 2 4 3"
You can output any set of legitimate solutions.
Sample input
5 53 53 24 23 45 1
Sample output
1 5 3 4 2 3
The principle of personal feeling is to make full use of search, or stack, or the nature of backtracking.
#include <cstdio>#include<cstdlib>#include<cstring>#include<iostream>using namespacestd;intdu[1010],used[5010],path[5010],n,m,cnt,tot=1;intlaxt[10010],next[10010],to[10010];voidAddintUintv) {next[++tot]=Laxt[u]; Laxt[u]=tot; To[tot]=v;}voidDfsintu) { for(intI=laxt[u];i;i=Next[i]) { if(!used[i/2]) {used[i/2]=1; DFS (To[i]); }} path[++cnt]=u;}intMain () {inti,u,v; scanf ("%d%d",&n,&m); for(i=1; i<=m;i++) {scanf ("%d%d",&u,&v); Add (u,v); add (V,u); Du[u]+ +;d u[v]++; } ints=1; for(i=1; i<=n;i++){ if(du[i]&1* p=i; } dfs (S); for(i=1; i<=cnt;i++) printf ("%d", Path[i]); return 0;}
HihoCoder1181 Oralu (Fleury algorithm to find Euler path)