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 <bits/stdc++.h>
#define DEBUG 0
using namespace std;
const int MAX_N = 5e5 + 10;
stack <pair <int, int>> graph[MAX_N];
vector <int> order;
bool used[MAX_N], is_print[MAX_N];
int visited[MAX_N];
void dfs(int u, int p) {
while(!graph[u].empty()) {
auto [v, i] = graph[u].top();
graph[u].pop();
if(v != p and used[i] == false) {
used[i] = true;
dfs(v, u);
}
}
order.push_back(u);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
for(int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
graph[u].emplace(v, i);
graph[v].emplace(u, i);
}
dfs(1, -1);
for(auto v : order) {
cout << v << ' ';
}
cout << '\n';
for(int i = 0; i < order.size(); i++) {
if(visited[order[i]] != 0) {
int j = i;
while(j >= visited[order[i]]) {
if(is_print[j] == false) {
cout << order[j] << ' ';
if(order[i] != order[j]) {
visited[order[j]] = 0;
}
is_print[j] = true;
}
j--;
}
cout << '\n';
}
visited[order[i]] = i + 1;
}
return 0;
}
Compilation message (stderr)
postmen.cpp: In function 'int main()':
postmen.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i = 0; i < order.size(); i++) {
| ~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |