Editorial for COCI '19 Contest 6 #2 Birmingham


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.

In order to score half of the points, we must first determine an array dist[a][b] which stores the shortest distances between pairs of nodes. We can do that by starting BFS from each node towards all other nodes. After that, we can do a special BFS from starting nodes that expands in the following way: if we are currently in node a with distance d, then we add all nodes to the queue which are not yet visited and are distant from a by \le (d-1) \times K. We can find these nodes by traversing dist[a].

To score all points it was enough to conclude that, if we know the distance from node x to some of the starting nodes, then we can deduce the solution for that node (either using a formula or a simple simulation). Distance from each node to the set of the starting nodes can be determined using BFS with all starting nodes being initially emplaced in our queue.


Comments

There are no comments at the moment.