All submissions for this problem are available.
The ship Titanic is very huge. It is often required by the staff to take things from 1 place to other.
Given the cost of possible paths through different levels, return the minimum cost of the path taken from the top level to the bottom level. ( It is not necessary that all the sectors are connected. There may be more than one direct path from one sector to another. There will always be a path from topmost level to lowest level. )
The first line contains two space separated integers n, k. Where n is the number of sectors on the topmost level, and k is the number of levels in the ship.
From the next line onwards, three space separated integers are given. First integer is the starting sector from 1st level, 2nd integer is the destination in the 2nd level, and 3rd integer is the cost of path. (The sources and destinitions are 1-based)
The integer -1 signifies the end of paths for the given pair of levels.
The next lines contain the paths for next pair of levels till a -1is encountered, and so on.
(So the total number of -1 encountered are k-1)
A single line containing the minimum cost to travel from topmost level to lowest level.
Input: 5 2 1 1 1 2 2 2 1 3 3 3 1 6 5 4 9 -1 Output: 1 Explanation: There are just two levels. The shortest path is from sector 1 on level 1 to sector 1 on level 2.
|Time Limit:||3 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.