#include <bits/stdc++.h>
using namespace std;
int in() {
char c=getchar_unlocked();
while(c<'0'||c>'9')
c=getchar_unlocked();
int r=0;
while(c>='0'&&c<='9') {
r=r*10+c-'0';
c=getchar_unlocked();
}
return r;
}
void out(int x) {
int lz=0, r=0;
while(x%10==0) {
++lz;
x/=10;
}
while(x) {
r=r*10+x%10;
x/=10;
}
while(r) {
putchar_unlocked('0'+r%10);
r/=10;
}
while(lz--)
putchar_unlocked('0');
}
const int mxN=5e5;
int n, m, eu[mxN], ev[mxN];
vector<int> adj[mxN], a1, a2;
bool a[mxN], b[mxN];
void dfs(int u) {
while(adj[u].size()) {
int e=adj[u].back();
adj[u].pop_back();
if(a[e])
continue;
a[e]=1;
dfs(eu[e]^ev[e]^u);
}
a1.push_back(u);
}
int main() {
n=in(), m=in();
for(int i=0; i<m; ++i) {
eu[i]=in()-1, ev[i]=in()-1;
adj[eu[i]].push_back(i);
adj[ev[i]].push_back(i);
}
dfs(0);
for(int i=0; i<a1.size(); ++i) {
if(b[a1[i]]) {
while(a2.back()!=a1[i]) {
out(a2.back()+1);
putchar_unlocked(' ');
b[a2.back()]=0;
a2.pop_back();
}
out(a1[i]+1);
putchar_unlocked('\n');
} else {
a2.push_back(a1[i]);
b[a1[i]]=1;
}
}
}
Compilation message
postmen.cpp: In function 'int main()':
postmen.cpp:59:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<a1.size(); ++i) {
~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
12152 KB |
Output is correct |
2 |
Correct |
15 ms |
12160 KB |
Output is correct |
3 |
Correct |
11 ms |
12136 KB |
Output is correct |
4 |
Correct |
12 ms |
12288 KB |
Output is correct |
5 |
Correct |
11 ms |
12160 KB |
Output is correct |
6 |
Correct |
11 ms |
12416 KB |
Output is correct |
7 |
Correct |
14 ms |
13056 KB |
Output is correct |
8 |
Correct |
12 ms |
12288 KB |
Output is correct |
9 |
Correct |
30 ms |
18040 KB |
Output is correct |
10 |
Correct |
15 ms |
12288 KB |
Output is correct |
11 |
Correct |
12 ms |
12392 KB |
Output is correct |
12 |
Correct |
32 ms |
18172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
12160 KB |
Output is correct |
2 |
Correct |
12 ms |
12032 KB |
Output is correct |
3 |
Correct |
12 ms |
12032 KB |
Output is correct |
4 |
Correct |
15 ms |
12288 KB |
Output is correct |
5 |
Correct |
11 ms |
12160 KB |
Output is correct |
6 |
Correct |
15 ms |
12416 KB |
Output is correct |
7 |
Correct |
14 ms |
13056 KB |
Output is correct |
8 |
Correct |
15 ms |
12288 KB |
Output is correct |
9 |
Correct |
35 ms |
18040 KB |
Output is correct |
10 |
Correct |
13 ms |
12264 KB |
Output is correct |
11 |
Correct |
11 ms |
12288 KB |
Output is correct |
12 |
Correct |
37 ms |
18168 KB |
Output is correct |
13 |
Correct |
58 ms |
20828 KB |
Output is correct |
14 |
Correct |
51 ms |
18420 KB |
Output is correct |
15 |
Correct |
61 ms |
19544 KB |
Output is correct |
16 |
Correct |
68 ms |
20896 KB |
Output is correct |
17 |
Correct |
64 ms |
16752 KB |
Output is correct |
18 |
Correct |
56 ms |
18932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
12032 KB |
Output is correct |
2 |
Correct |
12 ms |
12032 KB |
Output is correct |
3 |
Correct |
12 ms |
12136 KB |
Output is correct |
4 |
Correct |
17 ms |
12288 KB |
Output is correct |
5 |
Correct |
12 ms |
12160 KB |
Output is correct |
6 |
Correct |
14 ms |
12416 KB |
Output is correct |
7 |
Correct |
15 ms |
13140 KB |
Output is correct |
8 |
Correct |
12 ms |
12288 KB |
Output is correct |
9 |
Correct |
29 ms |
18040 KB |
Output is correct |
10 |
Correct |
15 ms |
12264 KB |
Output is correct |
11 |
Correct |
13 ms |
12288 KB |
Output is correct |
12 |
Correct |
35 ms |
18172 KB |
Output is correct |
13 |
Correct |
64 ms |
20852 KB |
Output is correct |
14 |
Correct |
50 ms |
18420 KB |
Output is correct |
15 |
Correct |
48 ms |
19568 KB |
Output is correct |
16 |
Correct |
65 ms |
20848 KB |
Output is correct |
17 |
Correct |
60 ms |
16752 KB |
Output is correct |
18 |
Correct |
58 ms |
18932 KB |
Output is correct |
19 |
Correct |
448 ms |
55668 KB |
Output is correct |
20 |
Correct |
395 ms |
44628 KB |
Output is correct |
21 |
Correct |
354 ms |
49804 KB |
Output is correct |
22 |
Correct |
447 ms |
56628 KB |
Output is correct |
23 |
Correct |
110 ms |
41560 KB |
Output is correct |
24 |
Correct |
443 ms |
35876 KB |
Output is correct |
25 |
Correct |
431 ms |
47464 KB |
Output is correct |