0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 18:08:47 +00:00

#2953. 「NOIP2018」旅行

https://loj.ac/s/1477645
This commit is contained in:
Baoshuo Ren 2022-06-07 16:34:23 +08:00
parent 8241ee6d51
commit 4d375dcd98
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
51 changed files with 250 additions and 0 deletions

100
LibreOJ/2953/2953.cpp Normal file
View File

@ -0,0 +1,100 @@
#include <algorithm>
#include <fstream>
#include <queue>
#include <unordered_map>
#include <vector>
std::ifstream cin("travel.in");
std::ofstream cout("travel.out");
const char endl = '\n';
const int N = 5005;
int n, m, s, t, in[N];
bool vis[N];
std::vector<int> c, g[N];
std::unordered_map<int, int> map[N];
void cycle() {
std::queue<int> q;
for (int i = 1; i <= n; i++) {
if (in[i] == 1) q.push(i);
}
while (!q.empty()) {
int u = q.front();
q.pop();
for (int v : g[u]) {
if (in[v] > 1) {
if (--in[v] == 1) q.push(v);
}
}
}
}
void dfs(int u, int fa, std::vector<int> &res) {
if (vis[u]) return;
vis[u] = true;
res.push_back(u);
for (int v : g[u]) {
if (v == fa || u == s && v == t || v == s && u == t) continue;
dfs(v, u, res);
}
vis[u] = false;
}
int main() {
cin >> n >> m;
for (int i = 1, u, v; i <= m; i++) {
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
in[u]++, in[v]++;
map[u][v] = map[v][u] = true;
}
cycle();
for (int i = 1; i <= n; i++) {
std::sort(g[i].begin(), g[i].end());
if (in[i] >= 2) c.push_back(i);
}
std::vector<int> ans;
if (n == m) {
ans = std::vector<int>(n, n);
for (int i = 0; i < c.size(); i++) {
for (int j = i + 1; j < c.size(); j++) {
s = c[i], t = c[j];
if (!map[s][t]) continue;
std::vector<int> res;
dfs(1, 0, res);
ans = std::min(ans, res);
}
}
} else {
dfs(1, 0, ans);
}
for (int &ans : ans) {
cout << ans << ' ';
}
cout << endl;
return 0;
}

BIN
LibreOJ/2953/data/travel1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel10.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel11.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel12.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel13.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel14.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel15.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel16.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel17.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel18.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel19.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel20.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel21.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel21.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel22.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel22.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel23.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel23.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel24.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel24.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel25.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel25.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel3.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel4.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel5.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel6.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel7.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel8.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel9.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2953/data/travel9.in (Stored with Git LFS) Normal file

Binary file not shown.