# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1074862 | RauPro | Senior Postmen (BOI14_postmen) | C++17 | 410 ms | 99528 KiB |
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>
using namespace std;
#define MOD 1000000007
#define MAX_NODES 500010
vector<pair<int, int>> AL[MAX_NODES];
bool visited[MAX_NODES];
bool edge_visited[MAX_NODES];
int index_tracker[MAX_NODES];
int ans[MAX_NODES];
void print(const vector<int>& prt) {
for (int i = 0; i < prt.size(); ++i) {
if (i > 0) cout << " ";
cout << prt[i];
}
cout << endl;
}
int dfs(int u, int size) {
visited[u] = true;
ans[size] = u;
while (index_tracker[u] < AL[u].size()) {
int v = AL[u][index_tracker[u]].first;
int edge_index = AL[u][index_tracker[u]].second;
index_tracker[u]++;
if (edge_visited[edge_index]) {
continue;
}
edge_visited[edge_index] = true;
if (!visited[v]) {
int returned_node = dfs(v, size + 1);
if (returned_node == u) {
continue;
} else {
visited[u] = false;
return returned_node;
}
} else {
vector<int> prt;
for (int j = size; j >= 0; --j) {
prt.push_back(ans[j]);
if (ans[j] == v) {
break;
}
}
print(prt);
visited[u] = false;
return v;
}
}
return 0;
}
void solve() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
AL[u].emplace_back(v, i);
AL[v].emplace_back(u, i);
//cout << u << " " << v << " " << i << endl;
}
for (int i = 1; i <= n; ++i) {
if (!visited[i]) {
dfs(i, 0);
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |