提交记录 12929
用户 | 题目 | 状态 | 得分 | 用时 | 内存 | 语言 | 代码长度 |
---|---|---|---|---|---|---|---|
lrw04 | noip18d. 【NOIP2018】旅行 | Accepted | 100 | 638.044 ms | 728 KB | C++11 | 1.65 KB |
提交时间 | 评测时间 |
---|---|
2020-07-04 23:13:09 | 2020-08-01 03:01:39 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;
#define MAXN 5020
#define MAXM (4 * MAXN)
#define INF 0x3f3f3f3f
int n, m, delu, delv;
int hd[MAXN], dst[MAXM], nxt[MAXM], ec = 1;
vector<int> g[MAXN], ans, cur;
bool vis[MAXN];
pair<int, int> edges[MAXM];
void link(int u, int v) {
nxt[++ec] = hd[u];
hd[u] = ec;
dst[ec] = v;
g[u].push_back(v);
}
void dfs(int s, int fa) {
ans.push_back(s);
for (int i = 0; i < (int) g[s].size(); i++)
if (g[s][i] != fa)
dfs(g[s][i], s);
}
void tree() {
dfs(1, 0);
for (int i = 0; i < n; i++)
cout << ans[i] << " ";
cout << endl;
}
inline bool notdel(int u, int v) {
return !((u == delu && v == delv) || (v == delu && u == delv));
}
void dfs_d(int u) {
// cerr << u << endl;
vis[u] = true;
cur.push_back(u);
for (int i = 0; i < (int) g[u].size(); i++)
if (!vis[g[u][i]] && notdel(u, g[u][i])) dfs_d(g[u][i]);
}
void loop() {
for (int i = 0; i < n; i++)
ans.push_back(INF);
for (int i = 0; i < m; i++) {
cur.clear();
memset(vis, false, sizeof(vis));
delu = edges[i].first;
delv = edges[i].second;
// cerr << delu << " " << delv << endl;
dfs_d(1);
if ((int) cur.size() == n && cur < ans) ans = cur;
// for (int i = 0; i < n; i++) cerr << cur[i] << " "; cerr << endl;
}
for (int i = 0; i < n; i++)
cout << ans[i] << " ";
cout << endl;
}
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int p, q;
cin >> p >> q;
link(p, q);
link(q, p);
edges[i] = make_pair(p, q);
}
for (int i = 1; i <= n; i++)
sort(g[i].begin(), g[i].end());
// cerr << "calc" << endl;
if (n == m) {
loop();
} else {
tree();
}
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 59.38 us | 172 KB | Accepted | Score: 4 | 显示更多 |
Testcase #2 | 64.9 us | 172 KB | Accepted | Score: 4 | 显示更多 |
Testcase #3 | 63.63 us | 172 KB | Accepted | Score: 4 | 显示更多 |
Testcase #4 | 95.75 us | 176 KB | Accepted | Score: 4 | 显示更多 |
Testcase #5 | 95.12 us | 176 KB | Accepted | Score: 4 | 显示更多 |
Testcase #6 | 466.83 us | 272 KB | Accepted | Score: 4 | 显示更多 |
Testcase #7 | 464.85 us | 276 KB | Accepted | Score: 4 | 显示更多 |
Testcase #8 | 467.71 us | 280 KB | Accepted | Score: 4 | 显示更多 |
Testcase #9 | 472.57 us | 264 KB | Accepted | Score: 4 | 显示更多 |
Testcase #10 | 473.36 us | 260 KB | Accepted | Score: 4 | 显示更多 |
Testcase #11 | 2.341 ms | 644 KB | Accepted | Score: 4 | 显示更多 |
Testcase #12 | 2.336 ms | 680 KB | Accepted | Score: 4 | 显示更多 |
Testcase #13 | 2.326 ms | 692 KB | Accepted | Score: 4 | 显示更多 |
Testcase #14 | 2.335 ms | 644 KB | Accepted | Score: 4 | 显示更多 |
Testcase #15 | 2.334 ms | 720 KB | Accepted | Score: 4 | 显示更多 |
Testcase #16 | 63.15 us | 176 KB | Accepted | Score: 4 | 显示更多 |
Testcase #17 | 64.49 us | 176 KB | Accepted | Score: 4 | 显示更多 |
Testcase #18 | 188.04 us | 184 KB | Accepted | Score: 4 | 显示更多 |
Testcase #19 | 188.64 us | 184 KB | Accepted | Score: 4 | 显示更多 |
Testcase #20 | 12.339 ms | 292 KB | Accepted | Score: 4 | 显示更多 |
Testcase #21 | 12.427 ms | 292 KB | Accepted | Score: 4 | 显示更多 |
Testcase #22 | 12.769 ms | 292 KB | Accepted | Score: 4 | 显示更多 |
Testcase #23 | 636.905 ms | 728 KB | Accepted | Score: 4 | 显示更多 |
Testcase #24 | 633.096 ms | 712 KB | Accepted | Score: 4 | 显示更多 |
Testcase #25 | 638.044 ms | 700 KB | Accepted | Score: 4 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-11-23 00:05:38 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠