# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
374307 | abra_stone | Senior Postmen (BOI14_postmen) | C++14 | 737 ms | 93604 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 <cstdio>
#include <vector>
#include <stack>
#define N 500005
using namespace std;
int n, m;
bool v[N], vi[N];
vector<int> gr[N], gi[N], ans;
stack<int> st;
void f(int p) {
int i;
while (gr[p].size() > 0) {
int ne = gr[p].back(), ni = gi[p].back();
gr[p].pop_back(); gi[p].pop_back();
if (vi[ni]) continue;
vi[ni] = 1;
f(ne);
}
ans.push_back(p);
}
int main()
{
int i, t1, t2;
cin >> n >> m;
for (i = 0; i < m; i++) {
scanf("%d %d", &t1, &t2);
gr[t1].push_back(t2); gi[t1].push_back(i);
gr[t2].push_back(t1); gi[t2].push_back(i);
}
f(1);
for (i = 0; i < ans.size(); i++) {
if (v[ans[i]]) {
printf("%d ", ans[i]);
while (!st.empty()) {
int tp = st.top();
if (tp == ans[i]) break;
st.pop();
v[tp] = 0;
printf("%d ", tp);
}
puts("");
} else {
v[ans[i]] = 1;
st.push(ans[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... |