From a36a2f6976c3bd0dd22bbab8be5db7c499581379 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 24 Jun 2022 19:47:02 +0800 Subject: [PATCH] =?UTF-8?q?P2731=20[USACO3.3]=E9=AA=91=E9=A9=AC=E4=BF=AE?= =?UTF-8?q?=E6=A0=85=E6=A0=8F=20Riding=20the=20Fences?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/77837475 --- Luogu/P2731/P2731.cpp | 61 ++++++++++++++++++++++++++++++++++++ Luogu/P2731/data/P2731_8.in | 3 ++ Luogu/P2731/data/P2731_8.out | 3 ++ 3 files changed, 67 insertions(+) create mode 100644 Luogu/P2731/P2731.cpp create mode 100644 Luogu/P2731/data/P2731_8.in create mode 100644 Luogu/P2731/data/P2731_8.out diff --git a/Luogu/P2731/P2731.cpp b/Luogu/P2731/P2731.cpp new file mode 100644 index 00000000..f231c45f --- /dev/null +++ b/Luogu/P2731/P2731.cpp @@ -0,0 +1,61 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 505; + +int m, g[N][N], d[N]; +int min = std::numeric_limits::max(), + max = std::numeric_limits::min(); +int cnt, ans[N << 2]; + +void dfs(int u) { + for (int i = min; i <= max; i++) { + if (g[u][i]) { + g[u][i]--, g[i][u]--; + + dfs(i); + } + } + + ans[++cnt] = u; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> m; + + while (m--) { + int u, v; + + cin >> u >> v; + + g[u][v]++, g[v][u]++; + d[u]++, d[v]++; + + min = std::min({min, u, v}); + max = std::max({max, u, v}); + } + + int s = min; + for (int i = min; i <= max; i++) { + if (d[i] & 1) { + s = i; + break; + } + } + + dfs(s); + + for (int i = cnt; i; i--) { + cout << ans[i] << endl; + } + + return 0; +} diff --git a/Luogu/P2731/data/P2731_8.in b/Luogu/P2731/data/P2731_8.in new file mode 100644 index 00000000..0e987dd4 --- /dev/null +++ b/Luogu/P2731/data/P2731_8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5fd7b39dbd43b341a50d0468f34b12fef4170e4a5a0b084387680308fe2f944b +size 8762 diff --git a/Luogu/P2731/data/P2731_8.out b/Luogu/P2731/data/P2731_8.out new file mode 100644 index 00000000..a6ec6d84 --- /dev/null +++ b/Luogu/P2731/data/P2731_8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e469449c6a4b17494c183d0ba5295454d2ade69d8ff767e179739e0d8f95a26a +size 4895