This page is still under construction.

Parts of this page are still being built. What you see may change.

Roadblock

Interview

Time limit1sMemory limit128 MB

Summary
Given a weighted undirected graph, double the length of one edge to maximize the increase in the shortest path from field 1 to field N.
Level

Medium6 of 10

Topics
Graph, Shortest path, Brute force, Greedy
Solved
No attempts yet

Problem

Every morning, Farmer John (FJ) walks across his farm from his house to the barn. The farm has NN fields (1≤N≤1001 \le N \le 100) connected by MM bidirectional paths (1≤M≤10,0001 \le M \le 10{,}000), each with a positive length. FJ's house is in field 11 and the barn is in field NN. No two fields are joined by more than one path, and every field is reachable from every other field. Whenever FJ travels, he always takes a route whose total length is minimum.

FJ's mischievous cows want to disrupt his morning walk. They will pile hay bales on exactly one of the MM paths, doubling that path's length. The cows want to choose the path so as to maximize the increase in the length of FJ's shortest route from the house to the barn. Determine the largest increase they can cause.

Input

  • Line 1: Two space-separated integers NN and MM.
  • Lines 2…M+12 \dots M+1: Line j+1j+1 describes the jj-th bidirectional path with three space-separated integers AjA_j, BjB_j, LjL_j. Fields AjA_j and BjB_j (each in 1…N1 \dots N) are joined by a path of length LjL_j (1≤Lj≤1,000,0001 \le L_j \le 1{,}000{,}000).

Output

  • Line 1: The maximum possible increase in the length of FJ's shortest route from field 11 to field NN that can be achieved by doubling the length of a single path.

Hint

In the sample there are 55 fields and 77 paths. Initially the shortest route from the house (field 11) to the barn (field 55) is 1→3→4→51 \to 3 \to 4 \to 5 with total length 1+3+2=61 + 3 + 2 = 6.

If the cows double the length of the path between fields 33 and 44 (from 33 to 66), FJ's shortest route becomes 1→3→51 \to 3 \to 5 with total length 1+7=81 + 7 = 8, which is 22 longer than before. No single path can force a larger increase, so the answer is 22.

Examples1

  1. Example 1

    Input
    5 7
    2 1 5
    1 3 1
    3 2 8
    3 5 7
    3 4 3
    2 4 7
    4 5 2
    
    Expected output
    2