#t518. 最短路径

最短路径

Shortest Path from a Source

Special for beginners, ^_^

Problem Description

Given a directed graph G=(V,E)G=(V,E) and a source vertex v0∈Vv_0\in V, write a program that outputs the shortest paths from v0v_0 to every other vertex in GG. Negative edge weights are allowed, as long as the total weight of every directed cycle is positive. Vertices are numbered from 11 to nn (nn is the number of vertices in GG).

Input Format

Line 11: a positive integer nn (2≤n≤802\le n\le80), the total number of vertices in GG.

Line 22: an integer, the source v0v_0 (v0∈Vv_0\in V; v0v_0 may be any vertex in GG).

Lines 33 through n+2n+2: the graph is given by an adjacency matrix WW. Path lengths are less than 101510^{15}.

Output Format

n−1n-1 lines in total, ordered by increasing vertex number. Each line outputs the shortest distance from the source v0v_0 to one vertex. Follow the sample for the exact format of each line.

Sample Input 1

5
1
0 2 - - 10
- 0 3 - 7
- - 0 4 -
- - - 0 5
- - 6 - 0

Sample Output 1

(1 -> 2) = 2
(1 -> 3) = 5
(1 -> 4) = 9
(1 -> 5) = 9

Hint

Constraints

1s, 1024KiB for each test case.