Road To Savings
InterviewTime limit1sMemory limit1024 MB
Given a road network, find the total length of roads that lie on no shortest path between the mayor's house a and office b.
- Level
Medium4 of 10
- Topics
- Shortest path, Graph
- Solved
- No attempts yet
Problem
Pat Wholes is in charge of road maintenance in Capitol City. The roads are in such poor shape that accidents happen almost every day, and the public is furious. Pat would like to pave every road in the city, but he also wants to keep his job. The mayor would replace him if the paving costs too much, so Pat must decide which roads to pave and which to leave alone. Since the mayor's happiness is the ultimate goal, Pat will pave only the roads that lie on a shortest path from the mayor's house to the mayor's office. Several equally short routes may exist, but many roads still lie on none of these paths, and Pat hopes that plenty of roads do not need paving. Pat came down to your basement cubicle to ask for the total length of the roads that do not need to be paved.
Input
Four positive integers are given on the first line (, ). Here is the number of intersections in the town, numbered 1 to , is the number of roads connecting the intersections, and and are the intersections where the mayor's house and office are located. Then lines follow, each containing three numbers (, , ), meaning a two-way road exists between intersections and with length . At most one road exists between any two intersections, and at least one path exists between and .
Output
Output the total length of all roads that do not need to be paved.