#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#define X first
#define Y second
#define PB push_back
using namespace std;
typedef pair < int, int > pii;
typedef vector < int > vi;
const int N = 5e5 + 5;
int bio[N], n, m, nod[N],ind[N], rek[N], cur;
vector < pii > v[N];
int tura[N], st[N], tr, ss;
inline bool is( char c ) { return c >= '0' && c <= '9'; }
inline int read_int( ) {
int num;
char c;
while( !is( c = getchar_unlocked( ) ) );
num = c - '0';
while( is( c = getchar_unlocked( ) ) ) num = num * 10 + c - '0';
return num;
}
void euler(){
rek[cur++] = 1;
for(;cur;){
int x = rek[cur - 1];
for(;ind[x] < v[x].size() && bio[v[x][ind[x]].Y];ind[x]++);
if(ind[x] == v[x].size()) cur--, tura[tr++] = x;
for(;ind[x] < v[x].size();ind[x]++){
if(bio[v[x][ind[x]].Y]) continue;
bio[v[x][ind[x]].Y] = 1;
int nxt = v[x][ind[x]].X;
rek[cur++] = nxt;
break;
}
}
}
void rastavi(){
memset(bio, 0, sizeof(bio));
for(int i = 0;i < tr;i++){
if(bio[tura[i]]){
while(st[ss - 1] != tura[i]){
printf("%d ", st[ss - 1]);
bio[st[ss - 1]]--;
ss--;
}
ss--;
bio[tura[i]]--;
printf("%d\n", tura[i]);
}
st[ss++] = tura[i];
bio[tura[i]]++;
}
}
int main(){
n = read_int(); m = read_int();
for(int i = 0;i < m;i++){
int x = read_int();
int y = read_int();
v[x].PB({y, i});
v[y].PB({x, i});
}
euler();
rastavi();
return 0;
}
Compilation message
postmen.cpp: In function 'void euler()':
postmen.cpp:36:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(;ind[x] < v[x].size() && bio[v[x][ind[x]].Y];ind[x]++);
~~~~~~~^~~~~~~~~~~~~
postmen.cpp:37:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(ind[x] == v[x].size()) cur--, tura[tr++] = x;
~~~~~~~^~~~~~~~~~~~~~
postmen.cpp:38:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(;ind[x] < v[x].size();ind[x]++){
~~~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
14080 KB |
Output is correct |
2 |
Correct |
13 ms |
14080 KB |
Output is correct |
3 |
Correct |
13 ms |
14080 KB |
Output is correct |
4 |
Correct |
15 ms |
14184 KB |
Output is correct |
5 |
Correct |
15 ms |
14128 KB |
Output is correct |
6 |
Correct |
15 ms |
14208 KB |
Output is correct |
7 |
Correct |
23 ms |
14592 KB |
Output is correct |
8 |
Correct |
14 ms |
14080 KB |
Output is correct |
9 |
Correct |
33 ms |
17152 KB |
Output is correct |
10 |
Correct |
13 ms |
14208 KB |
Output is correct |
11 |
Correct |
14 ms |
14208 KB |
Output is correct |
12 |
Correct |
39 ms |
17528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
14080 KB |
Output is correct |
2 |
Correct |
13 ms |
14080 KB |
Output is correct |
3 |
Correct |
16 ms |
14080 KB |
Output is correct |
4 |
Correct |
15 ms |
14208 KB |
Output is correct |
5 |
Correct |
13 ms |
14080 KB |
Output is correct |
6 |
Correct |
17 ms |
14208 KB |
Output is correct |
7 |
Correct |
17 ms |
14720 KB |
Output is correct |
8 |
Correct |
18 ms |
14080 KB |
Output is correct |
9 |
Correct |
33 ms |
17144 KB |
Output is correct |
10 |
Correct |
17 ms |
14208 KB |
Output is correct |
11 |
Correct |
13 ms |
14208 KB |
Output is correct |
12 |
Correct |
39 ms |
17528 KB |
Output is correct |
13 |
Correct |
69 ms |
19320 KB |
Output is correct |
14 |
Correct |
61 ms |
18552 KB |
Output is correct |
15 |
Correct |
61 ms |
18132 KB |
Output is correct |
16 |
Correct |
64 ms |
19320 KB |
Output is correct |
17 |
Correct |
59 ms |
18088 KB |
Output is correct |
18 |
Correct |
76 ms |
18528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14080 KB |
Output is correct |
2 |
Correct |
13 ms |
14080 KB |
Output is correct |
3 |
Correct |
12 ms |
14080 KB |
Output is correct |
4 |
Correct |
14 ms |
14208 KB |
Output is correct |
5 |
Correct |
15 ms |
14056 KB |
Output is correct |
6 |
Correct |
17 ms |
14208 KB |
Output is correct |
7 |
Correct |
19 ms |
14696 KB |
Output is correct |
8 |
Correct |
13 ms |
14208 KB |
Output is correct |
9 |
Correct |
47 ms |
17144 KB |
Output is correct |
10 |
Correct |
14 ms |
14080 KB |
Output is correct |
11 |
Correct |
13 ms |
14208 KB |
Output is correct |
12 |
Correct |
36 ms |
17528 KB |
Output is correct |
13 |
Correct |
67 ms |
19320 KB |
Output is correct |
14 |
Correct |
63 ms |
18552 KB |
Output is correct |
15 |
Correct |
71 ms |
18148 KB |
Output is correct |
16 |
Correct |
64 ms |
19296 KB |
Output is correct |
17 |
Correct |
68 ms |
18040 KB |
Output is correct |
18 |
Correct |
59 ms |
18584 KB |
Output is correct |
19 |
Correct |
405 ms |
40844 KB |
Output is correct |
20 |
Correct |
362 ms |
37124 KB |
Output is correct |
21 |
Correct |
388 ms |
34820 KB |
Output is correct |
22 |
Correct |
416 ms |
40848 KB |
Output is correct |
23 |
Correct |
136 ms |
28552 KB |
Output is correct |
24 |
Correct |
428 ms |
34548 KB |
Output is correct |
25 |
Correct |
400 ms |
37068 KB |
Output is correct |