题目要求是一个人要走遍一个农场,每条路都要走两次,但每次的方向都不同。其实就是给定n个点,m条边,双向欧拉回路。
#line 5"2230.cpp"
#include <iostream>
#include <vector>
using namespace std;
struct edge
{
int v;
bool flag;
};
struct edge temp;
vector <edge> map[10001];
void DFS(int x)
{
int i,j;
for(i=0; i<map[x].size(); i++)
{
if(map[x][i].flag == false)
{
map[x][i].flag = true;
DFS(map[x][i].v);
}
}
cout<<x<<endl;
}
int main()
{
int m,n,i,a,b;
while(cin>>n>>m)
{
for(i=0; i<m; i++)
{
cin>>a>>b;
temp.v = a;
temp.flag = false;
map[b].push_back(temp);
temp.v = b;
temp.flag = false;
map[a].push_back(temp);
}
DFS(1);
}
return 0;
}