# poj-1041-John's trip(计算欧拉路)

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <algorithm>
#define ll long long
using namespace std;
const int inf=0x3ffffff;
const int MAXN = 2003;
const int MAXM = 1000005;
const double eps = 1e-6;
bool vis[MAXM];

void add(int x, int y, int z) {
}

vector<int> path;

void dfs(int u) {
for (int i = 0; i < adj[u].size(); i++) {
}
}
}

bool solve() {
int origin = -1;
for (int i = 0; i < MAXN; i++) {
if (adj[i].size() % 2 == 1) {
// 无向图中存在欧拉回路的条件是各个节点度都是偶数
return false;
}
if (origin == -1) {
origin = i;
}
// 排序之后，保证最后找到的那条路是字典序最小的
}
}
path.clear();
memset(vis, false, sizeof(vis));
if (origin != -1) {
dfs(origin);
}
reverse(path.begin(), path.end());

return true;
}

int main() {
#ifndef ONLINE_JUDGE
freopen("1.txt", "r", stdin);
#endif
int i, j, k;
int x, y, z;
while(1) {
for (i = 0; i < MAXN; i++) {
}
scanf("%d%d", &x, &y);
if (x == 0 && y == 0) {
break;
}
do {
scanf("%d", &z);
scanf("%d%d", &x, &y);
} while(x && y);
if (solve()) {
for (int i = 0; i < path.size(); i++) {
printf("%d ", path[i]);
}
puts("");
} else {
puts("Round trip does not exist.");
}
}
return 0;
}

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客