"CF716D" Complete The Graph "shortest"

The meaning of problems

Given a \ (n-\) points \ (m \) without edges to view some of the edge weights temporarily \ (0 \) , you need to assign a \ ([1, 10 ^ {18}] \ ) number. Such that the final \ (S \) to \ (T \) the shortest path is \ (L \) , the output of a feasible allocation, or notify no solution.

\ (n \ leq 10 ^ 3 \) , \ (m \ leq 10 ^ 4 \) , \ (L \ leq 10 ^ 9 \)

answer

First, to get this figure, we \ (0 \) side into INF, seeking \ (S \) to \ (T \) Shortest \ (D \) , if this time \ (D <L \) , no solution

Then \ (0 \) side into \ (1 \) , find the shortest path \ (D \) , if the \ (D> L \) , no solution

The above two lines is obvious, we now prove that in addition to the above, certain solvability.

Consider \ (0 \) edge change \ (1 \) . Then all \ (S \) to \ (T \) path out by weight from small to large, then the first path \ (D \ Leq L \) . If \ (d = L \) is ended, otherwise this path must contain the variable edge. The variable edge +1 (which may lead to some path weight +1). Repeat the process solution can be obtained.

Guess you like

Origin www.cnblogs.com/hongzy/p/11514912.html