#t518. 最短路径
最短路径
Shortest Path from a Source
Special for beginners, ^_^
Problem Description
Given a directed graph and a source vertex , write a program that outputs the shortest paths from to every other vertex in . Negative edge weights are allowed, as long as the total weight of every directed cycle is positive. Vertices are numbered from to ( is the number of vertices in ).
Input Format
Line : a positive integer (), the total number of vertices in .
Line : an integer, the source (; may be any vertex in ).
Lines through : the graph is given by an adjacency matrix . Path lengths are less than .
Output Format
lines in total, ordered by increasing vertex number. Each line outputs the shortest distance from the source 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.