#P2176. [USACO11DEC] RoadBlock S / [USACO14FEB] Roadblock G/S

[USACO11DEC] RoadBlock S / [USACO14FEB] Roadblock G/S

Description

Every morning, FJ walks from his house across the farm to the barn. The farm consists of NN fields connected by MM bidirectional roads, each with a certain length. FJ’s house is at field 11, and the barn is at field NN. No two fields are connected by multiple roads, and the graph is connected. Whenever FJ travels between fields, he always takes a path with the minimum total length.

FJ’s cows, up to no good as always, decide to disrupt his morning routine. They place a stack of hay bales on one of the MM roads, doubling that road’s length. The cows want to choose a road to maximize the increase in FJ’s shortest path distance from home to the barn. They ask you to compute and report this maximum increase.

Input Format

Line 11: two integers N,MN, M.

Lines 22 to M+1M+1: the (i+1)(i+1)-th line contains three integers Ai,Bi,LiA_i, B_i, L_i. AiA_i and BiB_i are the indices of the fields connected by road ii, and LiL_i is the length of that road.

Output Format

A single integer: the maximum increase obtained by doubling exactly one road.

5 7
2 1 5
1 3 1
3 2 8
3 5 7
3 4 3
2 4 7
4 5 2
2

Hint

Sample explanation: If the length of the road between 33 and 44 is doubled, the shortest path changes from 13451 \rightarrow 3 \rightarrow 4 \rightarrow 5 to 1351 \rightarrow 3 \rightarrow 5.

Constraints:

  • For 30%30\% of the testdata, N70N \le 70, M1,500M \le 1{,}500.
  • For 100%100\% of the testdata, 1N1001 \le N \le 100, 1M5,0001 \le M \le 5{,}000, 1Li1,000,0001 \le L_i \le 1{,}000{,}000.

Translated by ChatGPT 5