# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
96702 | diamond_duke | Highway Tolls (IOI18_highway) | C++11 | 352 ms | 10584 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 "highway.h"
void find_pair(int n, std::vector<int> eu, std::vector<int> ev, int, int)
{
auto dis = ask(std::vector<int>(eu.size()));
auto find_edge = [&]
{
int l = 0, r = (int)eu.size() - 1, res = -1;
while (l <= r)
{
int m = l + r >> 1;
std::vector<int> vec(eu.size());
for (int i = 0; i <= m; i++)
vec[i] = 1;
if (ask(vec) > dis)
{
res = m;
r = m - 1;
}
else
l = m + 1;
}
return res;
};
std::vector<std::vector<int> > adj(n);
for (int i = 0; i < eu.size(); i++)
{
adj[eu[i]].push_back(i);
adj[ev[i]].push_back(i);
}
int e_sp = find_edge();
std::vector<int> vec_l = {eu[e_sp]}, vec_r = {ev[e_sp]};
std::vector<int> bel(n, -1), tree = {e_sp}, que = {eu[e_sp], ev[e_sp]};
bel[eu[e_sp]] = 0;
bel[ev[e_sp]] = 1;
for (int he = 0; he < que.size(); he++)
{
int u = que[he];
for (int e : adj[u])
{
int v = eu[e] ^ ev[e] ^ u;
if (~bel[v])
continue;
tree.push_back(e);
que.push_back(v);
bel[v] = bel[u];
(bel[v] ? vec_r : vec_l).push_back(v);
}
}
auto solve = [&] (std::vector<int> &node)
{
std::vector<int> idx(n, -1);
for (int i = 0; i < node.size(); i++)
idx[node[i]] = i;
int l = 0, r = (int)node.size() - 1, res = -1;
while (l <= r)
{
int m = l + r >> 1;
std::vector<int> vec(eu.size(), 1);
for (int e : tree)
vec[e] = idx[eu[e]] >= m || idx[ev[e]] >= m;
if (ask(vec) == dis)
r = m - 1;
else
{
res = m;
l = m + 1;
}
}
return node[res];
};
answer(solve(vec_l), solve(vec_r));
}
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... |