【题目链接】
http://poj.org/problem?id=2230
【算法】
欧拉回路
【代码】
#include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <exception> #include <fstream> #include <functional> #include <limits> #include <list> #include <map> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stdexcept> #include <streambuf> #include <string> #include <utility> #include <vector> #include <cwchar> #include <cwctype> #include <stack> #include <limits.h> using namespace std; #define MAXN 10010 #define MAXM 50010 struct Edge { int to,nxt; } e[MAXM<<1]; int i,n,m,u,v,tot; bool vis[MAXM<<1]; int head[MAXN]; inline void add(int u,int v) { tot++; e[tot] = (Edge){v,head[u]}; head[u] = tot; } inline void dfs(int u) { int i; for (i = head[u]; i; i = e[i].nxt) { if (!vis[i]) { vis[i] = true; dfs(e[i].to); } } printf("%d\n",u); } int main() { scanf("%d%d",&n,&m); for (i = 1; i <= m; i++) { scanf("%d%d",&u,&v); add(u,v); add(v,u); } dfs(1); return 0; }