#include <bits/stdc++.h>
#define X first
#define Y second
#define pb push_back
#define pii pair<int, int>
typedef long long ll;
using namespace std;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int OFF = (1 << 20);
int n, m, a, b;
vector<pii> s[500005];
vector<int> v;
vector<int> ost;
int bio[500005];
vector<int> rj[500005];
int sol = 0;
void dfs(int x) {
while (s[x].size() > 0) {
while (s[x].size() > 0 && s[x].back().Y == -1) s[x].pop_back();
if (s[x].size() == 0) break;
pii sus = s[x].back();
s[sus.X][sus.Y].Y = -1;
s[x].pop_back();
dfs(sus.X);
}
v.push_back(x);
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a >> b;
s[a].push_back({b, (int)s[b].size()});
s[b].push_back({a, (int)s[a].size()-1});
}
dfs(1);
reverse(v.begin(), v.end());
int kol = 0;
for (int i = 0; i < v.size(); i++) {
if (bio[v[i]]) {
rj[sol].push_back(v[i]);
while (ost.back() != v[i]) {
rj[sol].push_back(ost.back());
bio[ost.back()]--;
ost.pop_back();
}
kol += rj[sol].size();
sol++;
}
else {
bio[v[i]] = 1;
ost.push_back(v[i]);
}
}
if (kol != m) assert(0);
for (int i = 0; i < sol; i++) {
for (int j = 0; j < rj[i].size(); j++) cout << rj[i][j] << " ";
cout << "\n";
}
return 0;
}
Compilation message
postmen.cpp: In function 'int main()':
postmen.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
postmen.cpp:67:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int j = 0; j < rj[i].size(); j++) cout << rj[i][j] << " ";
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23800 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
13 ms |
24020 KB |
Output is correct |
5 |
Correct |
13 ms |
23876 KB |
Output is correct |
6 |
Correct |
13 ms |
24148 KB |
Output is correct |
7 |
Correct |
16 ms |
24936 KB |
Output is correct |
8 |
Correct |
13 ms |
24020 KB |
Output is correct |
9 |
Correct |
40 ms |
30048 KB |
Output is correct |
10 |
Correct |
14 ms |
23892 KB |
Output is correct |
11 |
Correct |
15 ms |
23892 KB |
Output is correct |
12 |
Correct |
44 ms |
30420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
13 ms |
23976 KB |
Output is correct |
5 |
Correct |
12 ms |
23892 KB |
Output is correct |
6 |
Correct |
13 ms |
24148 KB |
Output is correct |
7 |
Correct |
16 ms |
24916 KB |
Output is correct |
8 |
Correct |
12 ms |
23892 KB |
Output is correct |
9 |
Correct |
39 ms |
30020 KB |
Output is correct |
10 |
Correct |
12 ms |
23892 KB |
Output is correct |
11 |
Correct |
12 ms |
24012 KB |
Output is correct |
12 |
Correct |
42 ms |
30468 KB |
Output is correct |
13 |
Correct |
55 ms |
32240 KB |
Output is correct |
14 |
Correct |
55 ms |
30384 KB |
Output is correct |
15 |
Correct |
53 ms |
31696 KB |
Output is correct |
16 |
Correct |
56 ms |
32328 KB |
Output is correct |
17 |
Correct |
56 ms |
29088 KB |
Output is correct |
18 |
Correct |
55 ms |
31284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23812 KB |
Output is correct |
2 |
Correct |
12 ms |
23892 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
13 ms |
24020 KB |
Output is correct |
5 |
Correct |
14 ms |
23820 KB |
Output is correct |
6 |
Correct |
13 ms |
24148 KB |
Output is correct |
7 |
Correct |
16 ms |
24836 KB |
Output is correct |
8 |
Correct |
14 ms |
23892 KB |
Output is correct |
9 |
Correct |
40 ms |
30020 KB |
Output is correct |
10 |
Correct |
14 ms |
23892 KB |
Output is correct |
11 |
Correct |
13 ms |
23960 KB |
Output is correct |
12 |
Correct |
43 ms |
30428 KB |
Output is correct |
13 |
Correct |
61 ms |
32232 KB |
Output is correct |
14 |
Correct |
55 ms |
30276 KB |
Output is correct |
15 |
Correct |
57 ms |
31688 KB |
Output is correct |
16 |
Correct |
57 ms |
32244 KB |
Output is correct |
17 |
Correct |
57 ms |
29064 KB |
Output is correct |
18 |
Correct |
56 ms |
31232 KB |
Output is correct |
19 |
Correct |
361 ms |
66404 KB |
Output is correct |
20 |
Correct |
337 ms |
57144 KB |
Output is correct |
21 |
Correct |
325 ms |
63756 KB |
Output is correct |
22 |
Correct |
372 ms |
73004 KB |
Output is correct |
23 |
Correct |
157 ms |
58080 KB |
Output is correct |
24 |
Correct |
379 ms |
57064 KB |
Output is correct |
25 |
Correct |
355 ms |
67912 KB |
Output is correct |