# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
566626 | hoanghq2004 | Highway Tolls (IOI18_highway) | C++14 | 243 ms | 18688 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>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "highway.h"
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
void find_pair(int n, vector<int> U, vector<int> V, int A, int B) {
vector <vector <pair <int, int>>> g(n), e(n);
vector <int> ord(n), id(n, -1);
int m = U.size();
for (int i = 0; i < m; ++i) {
g[U[i]].push_back({V[i], i});
g[V[i]].push_back({U[i], i});
}
int L = 0, R = m - 1;
vector <int> w(m, 0);
long long tot = ask(w);
while (L < R) {
int mid = L + R >> 1;
vector <int> w(m, 0);
for (int i = mid + 1; i < m; ++i) w[i] = 1;
if (ask(w) != tot) L = mid + 1;
else R = mid;
}
int x = L;
queue <int> q;
q.push(U[x]);
q.push(V[x]);
vector <int> type(n, -1);
type[U[x]] = 0;
type[V[x]] = 1;
while (q.size()) {
int u = q.front();
q.pop();
for (auto [v, i]: g[u]) {
if (type[v] != -1) continue;
type[v] = type[u];
id[v] = i;
e[u].push_back({v, i});
q.push(v);
}
}
int ti = 0;
function <void(int)> dfs = [&](int u) {
ord[ti++] = u;
for (auto [v, i]: e[u]) {
dfs(v);
}
};
dfs(U[x]);
w.assign(m, -1);
for (int i = 0; i < n; ++i) {
if (i == U[x] || i == V[x]) continue;
w[id[i]] = 0;
}
w[x] = 0;
for (int i = 0; i < m; ++i) if (w[i] == -1) w[i] = 1;
tot = ask(w);
L = 0, R = ti - 1;
while (L < R) {
int mid = L + R >> 1;
vector <int> w(m, -1);
for (int i = 0; i <= mid; ++i) {
if (ord[i] == U[x] || ord[i] == V[x]) continue;
if (type[ord[i]] == 0) w[id[ord[i]]] = 0;
}
for (int i = 0; i < n; ++i) {
if (i == U[x] || i == V[x]) continue;
if (type[i] == 1) w[id[i]] = 0;
}
w[x] = 0;
for (int i = 0; i < m; ++i) if (w[i] == -1) w[i] = 1;
if (ask(w) == tot) R = mid;
else L = mid + 1;
}
int S = ord[L];
ti = 0;
dfs(V[x]);
L = 0, R = ti - 1;
while (L < R) {
int mid = L + R >> 1;
vector <int> w(m, -1);
for (int i = 0; i <= mid; ++i) {
if (ord[i] == U[x] || ord[i] == V[x]) continue;
if (type[ord[i]] == 1) w[id[ord[i]]] = 0;
}
for (int i = 0; i < n; ++i) {
if (i == U[x] || i == V[x]) continue;
if (type[i] == 0) w[id[i]] = 0;
}
w[x] = 0;
for (int i = 0; i < m; ++i) if (w[i] == -1) w[i] = 1;
if (ask(w) == tot) R = mid;
else L = mid + 1;
}
int T = ord[L];
answer(S, T);
}
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... |