提交记录 6952
用户 | 题目 | 状态 | 得分 | 用时 | 内存 | 语言 | 代码长度 |
---|---|---|---|---|---|---|---|
wys | noip18d. 【NOIP2018】旅行 | Accepted | 100 | 2.004 ms | 508 KB | C++ | 1.71 KB |
提交时间 | 评测时间 |
---|---|
2018-11-20 14:57:09 | 2020-08-01 00:54:51 |
// linear.cpp 18-10-28 wys
#include <stdio.h>
#include <algorithm>
const int MAXN = 300005;
int n, m;
struct edge {
int u, v, id;
};
bool operator < (const edge &a, const edge &b) {
return a.u < b.u || (a.u == b.u && a.v < b.v);
}
edge edges[MAXN * 2];
edge *first[MAXN];
int stack[MAXN];
int stack_eid[MAXN];
bool instack[MAXN];
int top;
bool found;
bool is_on_cycle[MAXN];
void dfs(int u, int last) {
stack[++top] = u;
instack[u] = true;
for (edge *e = first[u]; e->u == u; e++) {
int v = e->v;
if (v == last) continue;
if (instack[v]) {
found = true;
is_on_cycle[e->id] = true;
while (stack[top] != v) {
is_on_cycle[stack_eid[top - 1]] = true;
--top;
}
return;
}
stack_eid[top] = e->id;
dfs(v, u);
if (found) return;
}
instack[u] = false;
--top;
}
int ans_idx;
bool visit[MAXN];
bool del;
void dfs(int u) {
printf("%d%c", u, " \n"[++ans_idx == n]);
visit[u] = true;
++top;
bool done = false;
for (edge *e = first[u]; e->u == u; e++) {
int v = e->v;
if (visit[v]) continue;
edge *e1 = e + 1;
while (e1->u == u && visit[e1->v]) ++e1;
if (e1->u == u) {
stack[top] = e1->v;
} else {
--top;
done = true;
}
if (!del && is_on_cycle[e->id] && v > stack[top]) {
del = true;
} else {
dfs(v);
}
}
if (!done) --top;
}
int main() {
scanf("%d%d", &n, &m);
if (n == 1) {
return puts("1"), 0;
}
for (int i = 0; i < m; i++) {
int u, v;
scanf("%d%d", &u, &v);
edges[i * 2] = (edge){u, v, i};
edges[i * 2 + 1] = (edge){v, u, i};
}
std::sort(edges, edges + 2 * m);
first[1] = edges;
for (int i = 1; i < 2 * m; i++) {
if (edges[i].u != edges[i - 1].u) {
first[edges[i].u] = edges + i;
}
}
dfs(1, 0);
top = 0;
stack[0] = n + 1;
dfs(1);
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 14.94 us | 44 KB | Accepted | Score: 4 | 显示更多 |
Testcase #2 | 17.78 us | 44 KB | Accepted | Score: 4 | 显示更多 |
Testcase #3 | 19.15 us | 44 KB | Accepted | Score: 4 | 显示更多 |
Testcase #4 | 48.35 us | 64 KB | Accepted | Score: 4 | 显示更多 |
Testcase #5 | 46.31 us | 56 KB | Accepted | Score: 4 | 显示更多 |
Testcase #6 | 364.44 us | 132 KB | Accepted | Score: 4 | 显示更多 |
Testcase #7 | 364.45 us | 132 KB | Accepted | Score: 4 | 显示更多 |
Testcase #8 | 366.7 us | 136 KB | Accepted | Score: 4 | 显示更多 |
Testcase #9 | 379.76 us | 116 KB | Accepted | Score: 4 | 显示更多 |
Testcase #10 | 381.57 us | 112 KB | Accepted | Score: 4 | 显示更多 |
Testcase #11 | 2.004 ms | 400 KB | Accepted | Score: 4 | 显示更多 |
Testcase #12 | 1.992 ms | 456 KB | Accepted | Score: 4 | 显示更多 |
Testcase #13 | 1.986 ms | 472 KB | Accepted | Score: 4 | 显示更多 |
Testcase #14 | 1.988 ms | 396 KB | Accepted | Score: 4 | 显示更多 |
Testcase #15 | 1.98 ms | 508 KB | Accepted | Score: 4 | 显示更多 |
Testcase #16 | 15.23 us | 44 KB | Accepted | Score: 4 | 显示更多 |
Testcase #17 | 15.17 us | 44 KB | Accepted | Score: 4 | 显示更多 |
Testcase #18 | 46.01 us | 64 KB | Accepted | Score: 4 | 显示更多 |
Testcase #19 | 46.71 us | 64 KB | Accepted | Score: 4 | 显示更多 |
Testcase #20 | 363.53 us | 144 KB | Accepted | Score: 4 | 显示更多 |
Testcase #21 | 363.56 us | 144 KB | Accepted | Score: 4 | 显示更多 |
Testcase #22 | 363.06 us | 144 KB | Accepted | Score: 4 | 显示更多 |
Testcase #23 | 1.967 ms | 488 KB | Accepted | Score: 4 | 显示更多 |
Testcase #24 | 1.977 ms | 472 KB | Accepted | Score: 4 | 显示更多 |
Testcase #25 | 1.985 ms | 452 KB | Accepted | Score: 4 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-11-26 07:57:45 | Loaded in 3 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠