This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define N 500050
struct edge_t {
int v, f;
edge_t *nxt, *rev;
} e[N * 2], *adj[N], *ptr = e;
int vst[N], prv[N];
void addedge(int i, int j) {
edge_t* p = ptr++, *q = ptr++;
p->v = j, p->f = 0, p->nxt = adj[i], p->rev = q, adj[i] = p;
q->v = i, q->f = 0, q->nxt = adj[j], q->rev = p, adj[j] = q;
}
void dfs(int i) {
if(vst[i]) {
while(vst[i]) {
vst[i] = 0;
printf("%d ", i);
i = prv[i];
}
putchar('\n');
}
while(adj[i]) {
edge_t* p = adj[i]; adj[i] = adj[i]->nxt;
if(p->f) continue;
p->f = p->rev->f = 1;
vst[i] = 1;
prv[i] = p->v;
dfs(p->v);
}
}
int main() {
int n, m;
scanf("%d %d", &n, &m);
while(m--) {
int i, j;
scanf("%d %d", &i, &j);
addedge(i, j);
}
dfs(1);
return 0;
}
Compilation message (stderr)
postmen.cpp: In function 'int main()':
postmen.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
postmen.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%d %d", &i, &j);
| ~~~~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |