Cheapest route

Medium · Advanced graphs · Original CodeClash problem

Input has n and weighted undirected edges [u,v,w], w>0. Return shortest cost from 0 to n-1, or -1.

Input and output

One JSON value on a single line, with the fields described above. Read it using json.loads(input()).

One compact JSON value. Use print(json.dumps(answer, separators=(",", ":"))). Booleans must be JSON true/false. Arrays retain the stated order.

Examples

Example 1

Input: {"n":1,"edges":[]}
Output: 0

Example 2

Input: {"n":2,"edges":[]}
Output: -1

Constraints

Solve in Python

Sign in to save progress. Public example runs are unverified and do not affect ratings.