NIKKEI Programming Contest 2019-2 Task D. Shortest Path on a Line

Observations


$ from $ 1 to $ N $ is not necessarily the shortest turning back. The so-called road back means come to a small number of points from a large number of points.

Proof : First of all, the final step is definitely not any going back $ from $ 1 to $ N $ path. Assuming that there is a path from $ 1 $ to $ N $ is the shortest path to go back now, and let this road last repent $ from $ u to $ v $ and from $ v $ beginning until the end after point followed by $ v = v_0, v_1, \ dots v_k = N $. We have $ v <u <N $, $ v = v_0 <v_1 <v_2 <\ dots <v_k = N $ and $ v_i \ ne u $. Provided $ v_i <u $ and $ v_ {i + 1}> u $ is bound edge exists $ (u, v_ {i + 1}) $ and edges $ (v_i, v_ {i + 1}) $ equal in length, Thus take $ u, v_ {i + 1 }, \ dots, v_ {k} $ better. contradiction!

For convenience of description, the following with $ (u, v, C) $ indicates the connection $ u, V $, length $ C $ undirected edges, with $ (u \ to v, C) $ represents $ from $ u to $ v $ length $ c $ is directed edges.

Inferences can be drawn from the demonstrated: No original transformation in the following manner to FIG into a directed graph, from $ 1 to $ N $ $ shortest length unchanged:
the following set $ 1 \ le u <v \ le N $. The artwork in the side to delete non-$ $ (u, v, C) , have added to the edge $ (u \ to v, C ) $.
Optionally further addition of the length of the back side of the non-negative.

Considering the above there is a special case of the graph: for $ i = i, 2, \ dots, N $, plus the length of the back side of $ 0 $ $ (i \ to i - 1 , 0) $.
Noting this point for a group of the side $ (s \ to t, C_i ) $, $ L_i \ le s <t \ le R_i $, leaving only $ (L_i \ to R_i, C_i ) $ 1 $ can keep from $ $ N $ to the shortest path length constant.

Guess you like

Origin www.cnblogs.com/Patt/p/11828545.html