Editorial for IOI '18 P5 - Highway Tolls
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Subtask 1
- Test every possible
.
Subtask 2
- Sort the vertices by the distance from
. Then
can be found using binary search.
Subtask 3
- Binary search.
Subtask 4
- One function call with weight of every edge
to find the distance between
and
in unweighted
.
- An edge
on the shortest path between
and
can be found using binary search.
- After removing
, the graph will be separated into two subtrees. Then you can perform the solution of Subtask 2 twice to find
and
separately.
- Centroid decomposition is possible but implementation will be tough.
Subtask 5
- Let
be a subset of
, where
is the set of vertices in
.
- We set the weight of edges between
and
to
. The weights of other edges are set to
. Then, we can tell whether exactly one of
and
belongs to
by looking at the parity of the answer to the call.
- Thus we can compute
. Using this, we can also find
and
themselves.
Subtask 6
- Solution A: 21 points
- A vertex
on a shortest path between
and
can be found using binary search.
- Construct a BFS tree with root
. Then, we can use binary search again to find one of
and
.
- The other can be found similarly.
- A vertex
- Solution B: 31 points
- Find an edge
on a shortest path between
and
as in Subtask 4.
- Let
. Without loss of generality, we can assume
,
,
and
appears in this order on this shortest path.
- Then we can prove that
is strictly closer to
than to
. Similarly,
is closer to
than to
.
- Thus we have disjoint candidate sets
and
such that
and
are contained in
and
, respectively. At the same time, we can construct BFS trees of vertex sets
and
with roots
and
, respectively. We can suppose a shortest path goes only through
and edges in the BFS trees.
- Now we can find
and
as in the last part of Subtask 4.
- Find an edge
Comments