Weighted Paths on NetworkX X15175


Statement
 

networkx

pdf   zip

html

Given a directed graph with n vertices and m weighted arcs, we wish to know the cost of the minimum-cost directed path between two given vertices, if there is one.

Input

Input starts with n and m. Then follow m 3-tuples u,v,w, with uv, indicating an arc from u to v with weight w. The following will be true: there are no repeated arcs, all weights are positive integers, 0 ≤ u < n and 0 ≤ v < n. Finally, there follows a pair x, y with 0 ≤ x < n and 0 ≤ y < n.

Output

Write the total cost (sum of arc weights) of the path from x to y of least cost, if one exists; otherwise, write “no path”.

Observation

We are authorized to employ the NetworkX library.

Public test cases
  • Input

    8 10
    1 4 2
    4 6 1
    7 2 1
    7 5 2
    0 3 7
    2 5 9
    5 2 6
    6 3 1
    1 0 8
    0 1 5
    1 3

    Output

    4
    
  • Input

    8 10
    1 4 2
    4 6 1
    7 2 1
    7 5 2
    0 3 7
    2 5 9
    5 2 6
    6 3 1
    1 0 8
    0 1 5
    7 6

    Output

    no path
    
  • Information
    Author
    Language
    English
    Official solutions
    Python
    User solutions
    Python