# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
656492 | 600Mihnea | Senior Postmen (BOI14_postmen) | C++17 | 405 ms | 75488 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.
bool home = 0;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 500000 + 7;
int n;
int m;
int sum[N];
bool vis[N];
vector<int> g[N];
vector<int> ord;
void go(int a) {
while (!g[a].empty()) {
int i = g[a].back();
g[a].pop_back();
if (vis[i]) {
continue;
}
vis[i] = 1;
go(sum[i] - a);
ord.push_back(a);
}
}
signed main() {
if (home == 0) {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
} else {
freopen ("___input___.txt", "r", stdin);
}
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
sum[i] = a + b;
g[a].push_back(i);
g[b].push_back(i);
}
go(1);
for (int i = 1; i <= m; i++) {
assert(vis[i]);
}
for (int i = 1; i <= n; i++) {
vis[i] = 0;
}
assert((int) ord.size() == m);
assert(!ord.empty());
ord.push_back(ord[0]);
vector<int> stk;
for (auto &x : ord) {
if (vis[x] == 0) {
stk.push_back(x);
vis[x] = 1;
continue;
}
cout << x << " ";
while (stk.back() != x) {
cout << stk.back() << " ";
vis[stk.back()] = 0;
stk.pop_back();
}
cout << "\n";
}
return 0;
while ((int) ord.size() > 1) {
int dim = (int) ord.size();
set<int> s;
for (int r = 0; r < dim; r++) {
int x = ord[r];
if (s.count(x)) {
s.clear();
int l = r;
s.insert(ord[l]);
while (!s.count(ord[l - 1])) {
l--;
s.insert(ord[l]);
}
vector<int> new_ord, now;
for (int j = 0; j < dim; j++) {
if (l <= j && j <= r) {
now.push_back(ord[j]);
continue;
}
new_ord.push_back(ord[j]);
}
for (auto &v : now) {
cout << v << " ";
}
cout << "\n";
ord = new_ord;
break;
} else {
s.insert(x);
}
}
}
if (0) {
cout << " ---> ";
for (auto &x : ord) {
cout << x << " ";
}
cout << "\n";
}
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... |