Weighted shortest path (2)

Write a program that, given a directed graph with positive costs at the arcs, and two vertices xx and yy, prints the path of minimum cost that goes from xx to yy.

Input

Input consists of several cases. Every case begins with the number of vertices nn and the number of arcs mm. Follow mm triples u,v,cu, v, c, indicating that there is an arc u→vu \to v of cost cc, where u≠vu \ne v and 1≤c≤1041 \le c \le 10^4. Finally, we have xx and yy. Assume 1≤n≤1041 \le n \le 10^4, 0≤m≤5n0 \le m \le 5n, and that for every pair of vertices uu and vv there is at most one arc of the kind u→vu \to v. All numbers are integers. Vertices are numbered from 0 to n−1n-1. If yy is reachable from xx, you have the guarantee that there is a unique path.

The condition for cc was previously c≤1000c \le 1000. It was updated to create new test cases.

Output

For every case, print the path of minimum cost that goes from xx to yy. If there is no path from xx to yy, state so.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T10:08:16.197Z

© Jutge.org, 2006–2026.
https://jutge.org