I have been practicing problems on graphs and shortest paths and I encountered a problem that I'm struggling to understand.
Can you give me any tips and/or can you confirm that I got the general concept of the problem right?
In a given undirected weighted graph $G=(V,E)$ and an integer $k$ and edges with positive weights, the starting point is node $v_0$. You have to visit every node from $v_0, v_1, v_2, \dots, v_{k-1}$. If you visit any of those $k$ nodes you are allowed to create a portal in them. You can only make portals in those $k$ nodes. From one portal you can teleport to any other without any cost to the path.
You have to create a function
double shortestPath(int k)
that returns a shortest path to visit all $k$ nodes using teleportation system (if necessary).
I sketched this graph and tried to understand the problem here. Lets say we have to visit nodes 0,1 and 2.
Edited (Please check the reply to see better example of the problem)
My approach is this: If I take this route $0 \to 5$ (cost 1) then $5 \to 4$ (cost 2), $4 \to 2$ (cost 3) and then jump from $2 \to 0$ and go $0 \to 1$ (cost 9). This is the shortest path using teleportations.
Can someone tell me if I understood this problem correctly and maybe give some tips on how to implement the algorithm?