# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
734548 | DAleksa | Senior Postmen (BOI14_postmen) | C++17 | 454 ms | 77552 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;
struct edge {
int v;
int id;
};
const int N = 5e5 + 10;
vector<edge> g[N];
int n, m;
vector<int> eulerian_cycle;
bool mark[N];
int cnt[N];
int id = 0;
stack<int> stk;
int idx[N];
void find_eulerian_cycle(int u) {
for(; idx[u] < (int)g[u].size(); idx[u]++) {
edge v = g[u][idx[u]];
if(mark[v.id]) continue;
mark[v.id] = true;
find_eulerian_cycle(v.v);
eulerian_cycle.push_back(v.v);
}
}
int main() {
scanf("%d%d", &n, &m);
for(int i = 0; i < m; i++) {
int u, v;
scanf("%d%d", &u, &v);
// int I = i / 3;
// if(i % 3 == 0) {
// u = 1;
// v = 2 * I + 2;
// } else if(i % 3 == 1) {
// u = 1;
// v = 2 * I + 3;
// } else {
// u = 2 * I + 2;
// v = 2 * I + 3;
// }
g[u].push_back({v, id});
g[v].push_back({u, id++});
}
find_eulerian_cycle(1);
eulerian_cycle.push_back(1);
//for(int i = 0; i < eulerian_cycle.size(); i++) printf("%d ", eulerian_cycle[i]);
//printf("\n\n");
stk.push(eulerian_cycle[0]);
cnt[eulerian_cycle[0]]++;
for(int i = 1; i < eulerian_cycle.size(); i++) {
if(cnt[eulerian_cycle[i]] > 0) {
printf("%d ", eulerian_cycle[i]);
while(stk.top() != eulerian_cycle[i]) {
printf("%d ", stk.top());
cnt[stk.top()]--;
stk.pop();
}
printf("\n");
} else {
cnt[eulerian_cycle[i]]++;
stk.push(eulerian_cycle[i]);
}
}
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... |