Under construction

Still being built. Things may change

Road To Savings

Interview

Time limit1sMemory limit1024 MB

Summary
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 nn mm aa bb are given on the first line (n,a,b≤100n, a, b \leq 100, a≠ba \neq b). Here nn is the number of intersections in the town, numbered 1 to nn, mm is the number of roads connecting the intersections, and aa and bb are the intersections where the mayor's house and office are located. Then mm lines follow, each containing three numbers i1i_1 i2i_2 ℓ\ell (1≤i1,i2≤n1 \leq i_1, i_2 \leq n, i1≠i2i_1 \neq i_2, 1≤ℓ≤1001 \leq \ell \leq 100), meaning a two-way road exists between intersections i1i_1 and i2i_2 with length ℓ\ell. At most one road exists between any two intersections, and at least one path exists between aa and bb.

Output

Output the total length of all roads that do not need to be paved.

Examples2

  1. Example 1

    Input
    4 5 1 4
    1 2 1
    1 3 2
    1 4 2
    4 2 1
    3 4 1
    
    Expected output
    3
    
  2. Example 2

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