Editorial for COCI '19 Contest 6 #2 Birmingham
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 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 , then we add all nodes to the queue which are not yet visited and are distant from by . We can find these nodes by traversing .
To score all points it was enough to conclude that, if we know the distance from node 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