# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
102845 | wxh010910 | Highway Tolls (IOI18_highway) | C++17 | 347 ms | 11068 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>
#include "highway.h"
using namespace std;
void find_pair(int n, vector<int> u, vector<int> v, int a, int b) {
vector<vector<pair<int, int>>> adj(n);
int m = u.size();
vector<int> w(m);
for (int i = 0; i < m; ++i) {
adj[u[i]].emplace_back(v[i], i);
adj[v[i]].emplace_back(u[i], i);
}
long long value = ask(w);
int l = 0, r = m - 2, e = m - 1;
while (l <= r) {
int mid = l + r >> 1;
for (int i = 0; i < m; ++i) {
w[i] = i <= mid;
}
if (ask(w) != value) {
e = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
vector<int> tree, left, right, visit(n);
queue<int> q;
q.push(u[e]);
visit[u[e]] = 1;
left.push_back(u[e]);
q.push(v[e]);
visit[v[e]] = 2;
right.push_back(v[e]);
tree.push_back(e);
while (!q.empty()) {
int x = q.front();
q.pop();
for (auto p : adj[x]) {
int y = p.first, w = p.second;
if (!visit[y]) {
tree.push_back(w);
q.push(y);
if (visit[x] == 1) {
visit[y] = 1;
left.push_back(y);
} else {
visit[y] = 2;
right.push_back(y);
}
}
}
}
auto solve = [&](vector<int> nodes) {
int l = 0, r = nodes.size() - 2, p = nodes.size() - 1;
while (l <= r) {
int mid = l + r >> 1;
vector<bool> ban(n, false);
for (int i = mid + 1; i < nodes.size(); ++i) {
ban[nodes[i]] = true;
}
for (int i = 0; i < m; ++i) {
w[i] = 1;
}
for (auto e : tree) {
if (!ban[u[e]] && !ban[v[e]]) {
w[e] = 0;
}
}
if (ask(w) == value) {
p = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
return nodes[p];
};
answer(solve(left), solve(right));
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |