提交记录 9130
提交时间 |
评测时间 |
2019-04-13 21:18:05 |
2020-08-01 01:32:54 |
#include <stdio.h>
#include <algorithm>
const int MAXN = 500005;
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 | 13.77 us | 44 KB | Accepted | Score: 5 | 显示更多 |
Testcase #2 | 12.92 us | 44 KB | Accepted | Score: 5 | 显示更多 |
Testcase #3 | 46.85 us | 52 KB | Accepted | Score: 5 | 显示更多 |
Testcase #4 | 45.19 us | 52 KB | Accepted | Score: 5 | 显示更多 |
Testcase #5 | 1.958 ms | 424 KB | Accepted | Score: 5 | 显示更多 |
Testcase #6 | 1.949 ms | 400 KB | Accepted | Score: 5 | 显示更多 |
Testcase #7 | 47.174 ms | 7 MB + 200 KB | Accepted | Score: 5 | 显示更多 |
Testcase #8 | 47.374 ms | 5 MB + 1000 KB | Accepted | Score: 5 | 显示更多 |
Testcase #9 | 348.346 ms | 36 MB + 492 KB | Accepted | Score: 5 | 显示更多 |
Testcase #10 | 352.916 ms | 39 MB + 664 KB | Accepted | Score: 5 | 显示更多 |
Testcase #11 | 352.606 ms | 30 MB + 456 KB | Accepted | Score: 5 | 显示更多 |
Testcase #12 | 355.344 ms | 33 MB + 892 KB | Accepted | Score: 5 | 显示更多 |
Testcase #13 | 1.995 ms | 436 KB | Accepted | Score: 5 | 显示更多 |
Testcase #14 | 1.972 ms | 500 KB | Accepted | Score: 5 | 显示更多 |
Testcase #15 | 46.214 ms | 7 MB + 1000 KB | Accepted | Score: 5 | 显示更多 |
Testcase #16 | 46.537 ms | 8 MB + 688 KB | Accepted | Score: 5 | 显示更多 |
Testcase #17 | 347.498 ms | 54 MB + 272 KB | Accepted | Score: 5 | 显示更多 |
Testcase #18 | 347.238 ms | 54 MB + 272 KB | Accepted | Score: 5 | 显示更多 |
Testcase #19 | 329.11 ms | 37 MB + 844 KB | Accepted | Score: 5 | 显示更多 |
Testcase #20 | 341.364 ms | 46 MB + 1020 KB | Accepted | Score: 5 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-11-25 23:04:11 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠