Editorial for COCI '12 Contest 5 #4 Hipercijevi
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 nodes and 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 nodes and edges. A breadth-first search applied to this graph yields the solution , where is the number of stations on the shortest path from station to station .
Comments