G - Road Blocked 2 Editorial
by
LinLeXiao
Alternative Solution
It’s easy to calculate the number of different shortest paths from a certain starting point using Dijkstra.
Let’s say represents the number of different shortest paths from vertex to vertex , and represents the minimal distance from vertex to vertex .
Similarly, let represent the number of different shortest paths from vertex to vertex , and represent the minimal distance from vertex to vertex .
A key insight is that, for a bidirectional edge with weight , if the number of shortest path from to that pass equals implies all shortest paths include this edge, thus the answer is Yes
.
Specifically, the answer for such an edge is Yes
if either of the following holds:
and
and
The only problem is that the number of different shortest paths may be too large to store. To solve this, use multi-hashing, and the problem can be easily solved.
posted:
last update: