Editorial for COCI '12 Contest 5 #4 Hipercijevi


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.

The graph described in the problem statement is a hypergraph. When solving the shortest path problem on a hypergraph, we can convert it to a "normal" undirected graph by simply connecting all pairs of nodes (stations) on the same hyperedge (hypertube) with undirected edges. This results in a graph with a total of N nodes and M \times K \times (K-1)/2 edges. A simple breadth-first search applied to this graph is then a solution, ignoring time and memory constraints.

However, the constraints prevent such a solution from obtaining all points. The most elegant way to speed up the solution is adding a new node for each hypertube, connecting it with undirected edges to all stations connected to the corresponding hypertube. Such a graph has N+M nodes and M \times K edges. A breadth-first search applied to this graph yields the solution 2X-1, where X is the number of stations on the shortest path from station 1 to station N.


Comments

There are no comments at the moment.