PKU 2230 Watchcow

http://poj.org/problem?id=2230
n個のノードとm個のエッジをもつグラフ上の、すべてのエッジを2回通る経路を出力しろというような問題。

dfsする。

vector<PI> G[10000];
bool use[50000];

void dfs(int v){
  printf("%d\n",v+1);
  FOR(it,G[v]){
    if(use[it->S])continue;
    use[it->S]=true;
    dfs(it->F);
    printf("%d\n",v+1);
  }
}

main(){
  int n,m;
  cin>>n>>m;
  rep(i,m){
    int a,b;
    scanf("%d%d",&a,&b);
    --a,--b;
    G[a].pb(mp(b,i));
    G[b].pb(mp(a,i));
  }
  dfs(0);
}