0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 20:05:26 +00:00

P2731 [USACO3.3]骑马修栅栏 Riding the Fences

https://www.luogu.com.cn/record/77837475
This commit is contained in:
Baoshuo Ren 2022-06-24 19:47:02 +08:00
parent 799b57e9f4
commit a36a2f6976
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
3 changed files with 67 additions and 0 deletions

61
Luogu/P2731/P2731.cpp Normal file
View File

@ -0,0 +1,61 @@
#include <iostream>
#include <algorithm>
#include <limits>
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<int>::max(),
max = std::numeric_limits<int>::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;
}

BIN
Luogu/P2731/data/P2731_8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2731/data/P2731_8.out (Stored with Git LFS) Normal file

Binary file not shown.