# Include <iostream>
# Include <string. h>
Using namespace STD;
Int f [1050] [1050], d [1050], Res [1550000];
Int N, j = 0, K = 0, m = 0;
Void search (int z)
{
For (INT I = 1; I <= m; I ++)
If (F [Z] [I]> 0)
{F [Z] [I] --;
F [I] [Z] --;
Search (I );
}
J ++;
Res [J] = z;
}
Int main (){
Cin> N;
For (INT I = 1; I <= N; I ++)
{Int X, Y;
Cin> x> Y;
F [x] [Y] ++;
F [y] [x] ++;
D [x] ++; d [y] ++;
M = max (x, m), y );
}
For (INT I = 1; I <= m; I ++)
If (d [I] % 2! = 0)
{K = I; break ;}
If (k = 0)
{
For (INT I = 1; I <= N; I ++)
If (d [I])
{K = I; break ;}}
Search (k );
For (INT I = J; I> 0; I --)
Cout <res [I] <Endl;
Return 0;
}
The program written by this scum. The idea is to plagiarize a player in wikioi.
Now, let me review our ideas, strengthen our understanding, and consolidate our memories.
F [x] [Y] ++;
F [y] [x] ++; these two statements are very good. The subtraction behind them is the eye of this algorithm (for personal opinions, Do not spray ). This sentence indicates the path that has been recorded, and some are marked as 1. The subtraction in the function indicates that the path has been passed once and is marked as 0, so that it will not be repeated. After understanding this, the algorithm will understand more than half of it.
D [X], d [y] indicates the total number of lines (like a qualifying line) at this point ?) To identify the odd and even points (the outlet is odd or even ).
M = max (x, m), Y); for this sentence, the maximum value of the vertex that appears in the record is used to determine the vertex range.
For (INT I = 1; I <= m; I ++)
If (d [I] % 2! = 0)
{K = I; break ;}
If (k = 0)
{
For (INT I = 1; I <= N; I ++)
If (d [I])
{K = I; break ;}} this is to find out if there is any odd degree (Baidu can not understand the meaning of the odd degree for the Euler loop ), if there is an odd degree, a small odd degree is recorded. If not, the minimum even point is recorded.
Then, after finding the smallest odd (even) degree point, you can start to use the function!
Void search (int z)
{
For (INT I = 1; I <= m; I ++)
If (F [Z] [I]> 0)
{F [Z] [I] --;
F [I] [Z] --;
Search (I );
}
J ++;
Res [J] = z;
} Starting from the smallest odd (even) degree, find the line composed of the vertex size and its closest vertex, and record the line as 0 to avoid repetition. The following J ++ records the number of occurrences of the vertex.
Save it with res.
I still don't understand why I need inverted output at the end ,. I will try again later.
Thank you for your advice.