1 #include <stdio.h>
2 #include <vector>
3 #include <iostream>
4 using namespace std;
5
6
7 const int NumNode = 8 ;
8 vector<int> v[9];
9 enum colors
10 {
11 white , black , gray
12 }color[NumNode + 1];
13 void dfs( int i )
14 {
15 color[i] = gray ;
16 cout << i << endl;
17 for ( int j = 0 ; j < v[i].size() ; j++)
18 {
19 if ( color[v[i][j]] == white )
20 dfs( v[i][j]);
21 }
22
23 color[ i ] = black ;
24 }
25 int main()
26 {
27
28 int node1 , node2 ;
29 memset( color , white , sizeof(color ));
30 for ( int i = 0 ; i < 9 ; i++)
31 {
32 scanf("%d%d" , &node1 , &node2 );
33 v[node1].push_back(node2);
34 v[node2].push_back(node1);
35 }
36 for ( int i = 1 ; i <= 8 ; i ++)
37 if ( color[i] == white )
38 dfs(i);
39 cin >> node1 ;
40 return 0 ;
41 }