# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
260023 | anonymous | Senior Postmen (BOI14_postmen) | C++14 | 525 ms | 61412 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 <iostream>
#include <vector>
#include <utility>
#define MAXN 500005
using namespace std;
int N, M, del[MAXN], inStack[MAXN];
vector <pair<int,int> > adj[MAXN];
vector <int> S,S2;
void dfs(int u) { //Hierholzer
while (adj[u].size()) {
int v = adj[u].back().first, id = adj[u].back().second;
adj[u].pop_back();
if (!del[id]) {
del[id] = true;
dfs(v);
}
}
S.push_back(u);
}
int main() {
//freopen("seniorin.txt","r",stdin);
scanf("%d %d",&N,&M);
for (int i=1; i<=M; i++) {
int u,v;
scanf("%d %d",&u,&v);
adj[u].push_back({v,i});
adj[v].push_back({u,i});
}
dfs(1);
for (int i=0; i<S.size(); i++) {
if (inStack[S[i]]) {
while (S2.size() && S2.back() != S[i]) {
printf("%d ",S2.back());
inStack[S2.back()]--;
S2.pop_back();
}
printf("%d\n",S[i]);
} else {
inStack[S[i]]++;
S2.push_back(S[i]);
}
}
}
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... |