Two Paths
Time limit1sMemory limit512 MB
Given a weighted undirected graph, find the shortest walk from node 1 to node n that differs from Alice's chosen shortest path.
- Level
Medium7 of 10
- Topics
- Graph, Shortest path, Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
You are given an undirected graph with nodes (numbered from to ) and edges. Each edge has a length. The graph contains neither multiple edges nor self-loops.
Alice and Bob are playing a game. Each player has to pick a path from to (not necessarily a simple path). The paths have to be different.
Alice always moves first, and she is so clever that she took one of the shortest paths from to . Now it is Bob's turn. Bob wants to pick the shortest possible path from to which is different from Alice's path. Your task is to find the length of such path.
Two paths and are considered different if and only if they have different number of edges or there is an integer such that the -th edge of differs from the -th edge of .
Input
The first line of input contains two integers: the number of nodes and the number of edges (, ). Each of the next lines contains three integers , , and which mean that there is an edge between node and node , and its length is (, ). It is guaranteed that there is at least one path from to .
Output
Print a single line with a single integer: the length of a valid shortest path for Bob.