#include <stdio.h>
int ctrl[500005];
int nxt[1000005], prv[1000005], id[1000005];
int head[500005], en[500005];
bool visited[500005];
int n,m;
int euler[1000005], eulersize;
int q[1000005], qsize;
int read_int(){
char c;
bool check = 0;
int res = 0;
while(1){
c = getchar();
if (c == '-') {check = 1; continue;}
if (c == ' ' || c == '\n') break;
res = res*10 + c - '0';
}
if (check) return -res;
return res;
}
void dfs(){
q[qsize++] = 1;
while(qsize){
int u = q[qsize-1];
bool mjk = 0;
for(;ctrl[u];ctrl[u] = nxt[ctrl[u]]){
int v = (u ^ head[id[ctrl[u]]] ^ en[id[ctrl[u]]]);
if (visited[id[ctrl[u]]]) continue;
mjk = 1;
visited[id[ctrl[u]]] = 1;
q[qsize++] = v;
break;
}
if(mjk) continue;
euler[eulersize++] = u;
--qsize;
}
}
int st[1000005], stsize;
bool used[1000005];
int main(){
n = read_int();
m = read_int();
int cnt = 0;
for(int i=1;i<=m;++i){
int x = read_int(),y = read_int();
if (!ctrl[x]) ctrl[x] = ++cnt;
else nxt[prv[x]] = ++cnt;
id[cnt] = i;
prv[x] = cnt;
if (!ctrl[y]) ctrl[y] = ++cnt;
else nxt[prv[y]] = ++cnt;
id[cnt] = i;
prv[y] = cnt;
head[i] = x;
en[i] = y;
}
dfs();
for(int i=0;i<eulersize;++i){
if (used[euler[i]]){
while(st[stsize-1] != euler[i]){
printf("%d ",st[stsize-1]);
used[st[stsize-1]] = 0;
--stsize;
};
printf("%d\n",euler[i]);
}
else{
st[stsize++] = euler[i];
used[euler[i]] = 1;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
488 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
512 KB |
Output is correct |
7 |
Correct |
11 ms |
924 KB |
Output is correct |
8 |
Correct |
6 ms |
512 KB |
Output is correct |
9 |
Correct |
30 ms |
4016 KB |
Output is correct |
10 |
Correct |
6 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
34 ms |
4112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
7 ms |
512 KB |
Output is correct |
7 |
Correct |
8 ms |
896 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
33 ms |
3968 KB |
Output is correct |
10 |
Correct |
6 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
38 ms |
4064 KB |
Output is correct |
13 |
Correct |
48 ms |
5496 KB |
Output is correct |
14 |
Correct |
44 ms |
4856 KB |
Output is correct |
15 |
Correct |
36 ms |
4600 KB |
Output is correct |
16 |
Correct |
45 ms |
5484 KB |
Output is correct |
17 |
Correct |
44 ms |
4412 KB |
Output is correct |
18 |
Correct |
47 ms |
4848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
416 KB |
Output is correct |
6 |
Correct |
6 ms |
564 KB |
Output is correct |
7 |
Correct |
10 ms |
896 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
36 ms |
3964 KB |
Output is correct |
10 |
Correct |
6 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
36 ms |
4064 KB |
Output is correct |
13 |
Correct |
46 ms |
5496 KB |
Output is correct |
14 |
Correct |
40 ms |
4988 KB |
Output is correct |
15 |
Correct |
39 ms |
4600 KB |
Output is correct |
16 |
Correct |
42 ms |
5480 KB |
Output is correct |
17 |
Correct |
53 ms |
4448 KB |
Output is correct |
18 |
Correct |
48 ms |
4856 KB |
Output is correct |
19 |
Correct |
368 ms |
26300 KB |
Output is correct |
20 |
Correct |
352 ms |
23112 KB |
Output is correct |
21 |
Correct |
287 ms |
22000 KB |
Output is correct |
22 |
Correct |
355 ms |
26300 KB |
Output is correct |
23 |
Correct |
133 ms |
18424 KB |
Output is correct |
24 |
Correct |
392 ms |
20804 KB |
Output is correct |
25 |
Correct |
340 ms |
23104 KB |
Output is correct |