| 1 | multiset<int> adj[1010]; |
| 2 | list<int> L; |
| 3 | list<int>::iterator euler(int at, int to, |
| 4 | list<int>::iterator it) { |
| 5 | if (at == to) return it; |
| 6 | L.insert(it, at), --it; |
| 7 | while (!adj[at].empty()) { |
| 8 | int nxt = *adj[at].begin(); |
| 9 | adj[at].erase(adj[at].find(nxt)); |
| 10 | adj[nxt].erase(adj[nxt].find(at)); |
| 11 | if (to == -1) { |
| 12 | it = euler(nxt, at, it); |
| 13 | L.insert(it, at); |
| 14 | --it; |
| 15 | } else { |
| 16 | it = euler(nxt, to, it); |
| 17 | to = -1; } } |
| 18 | return it; } |
| 19 | // euler(0,-1,L.begin()) |
| 20 | // vim: cc=60 ts=2 sts=2 sw=2: |