# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
227157 | Bruteforceman | Senior Postmen (BOI14_postmen) | C++11 | 339 ms | 35320 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;
const int maxn = 5e5 + 10;
struct edge {
int l, r;
int nxtL, nxtR;
} e[maxn];
int idx[maxn];
int del[maxn];
int st[maxn];
int id;
void dfs(int x) {
while(idx[x] != -1) {
int i = idx[x];
int y = e[i].l ^ e[i].r ^ x;
idx[x] = (e[i].l == x) ? e[i].nxtL : e[i].nxtR;
if(del[i]) continue; del[i] = true;
dfs(y);
}
st[id++] = x;
}
int main() {
int n, m;
scanf("%d %d", &n, &m);
memset(idx, -1, sizeof idx);
for(int i = 0; i < m; i++) {
scanf("%d %d", &e[i].l, &e[i].r);
e[i].nxtL = idx[e[i].l];
e[i].nxtR = idx[e[i].r];
idx[e[i].l] = idx[e[i].r] = i;
}
dfs(1);
memset(del, false, sizeof del);
stack <int> s;
for(int i = 0; i < id; i++) {
int x = st[i];
s.push(x);
if(del[x]) {
do {
printf("%d ", s.top());
del[s.top()] = false;
s.pop();
} while(x != s.top() || !puts(""));
}
del[x] = true;
}
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... |