This page is still under construction.

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

Commuter Pass

Time limit2sMemory limit256 MB

Summary
Pick a shortest S-T path to make free, then find the minimum U-V travel cost, where edges on that path cost 0 and others cost their fare.
Level

Hard8 of 10

Topics
Graph, Shortest path, Dynamic programming
Solved
No attempts yet

Problem

JOI lives in a city with NN stations, numbered from 1 to NN. The city has MM railways, numbered from 1 to MM. Railway ii (1≤i≤M1 \le i \le M) connects station AiA_i and station BiB_i in both directions, and its fare is CiC_i yen.

JOI lives near station SS and attends IOI High School near station TT. He plans to buy a commuter pass between these two stations. When he buys the pass, he must choose one route between station SS and station TT whose cost is minimum. With this pass he can ride every railway on the chosen route in either direction at no extra charge.

JOI also often visits bookstores near station UU and station VV. He therefore wants to buy the pass so that the cost of traveling from station UU to station VV is minimized.

To travel from station UU to station VV, he first chooses a route from station UU to station VV. For each railway ii on that route he pays

  • 0 yen if railway ii is on the route chosen when he bought the pass, or
  • CiC_i yen if railway ii is not on the route chosen when he bought the pass.

The sum of these fares is the cost from station UU to station VV.

Write a program that computes the minimum cost from station UU to station VV when the route for the commuter pass is chosen appropriately.

Input

Read the following data from standard input.

  • The first line contains two integers NN and MM separated by a space. The city JOI lives in has NN stations and MM railways.
  • The second line contains two integers SS and TT separated by a space. JOI plans to buy a commuter pass between station SS and station TT.
  • The third line contains two integers UU and VV separated by a space. JOI wants to minimize the cost from station UU to station VV.
  • The ii-th of the following MM lines (1≤i≤M1 \le i \le M) contains three integers AiA_i, BiB_i, CiC_i separated by spaces. Railway ii connects station AiA_i and station BiB_i in both directions, and its fare is CiC_i yen.

Output

Print one line to standard output containing the minimum cost from station UU to station VV when the route for the commuter pass is chosen appropriately.

Constraints

  • 2≤N≤100 0002 \le N \le 100\,000
  • 1≤M≤200 0001 \le M \le 200\,000
  • 1≤S≤N1 \le S \le N
  • 1≤T≤N1 \le T \le N
  • 1≤U≤N1 \le U \le N
  • 1≤V≤N1 \le V \le N
  • S≠TS \ne T
  • U≠VU \ne V
  • S≠US \ne U or T≠VT \ne V
  • Every station is reachable from every other station by railways.
  • 1≤Ai<Bi≤N1 \le A_i < B_i \le N (1≤i≤M1 \le i \le M)
  • For every 1≤i<j≤M1 \le i < j \le M, Ai≠AjA_i \ne A_j or Bi≠BjB_i \ne B_j.
  • 1≤Ci≤1 000 000 0001 \le C_i \le 1\,000\,000\,000 (1≤i≤M1 \le i \le M)

Examples5

  1. Example 1

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

    Input
    6 5
    1 2
    3 6
    1 2 1000000000
    2 3 1000000000
    3 4 1000000000
    4 5 1000000000
    5 6 1000000000
    
    Expected output
    3000000000
    
  3. Example 3

    Input
    8 8
    5 7
    6 8
    1 2 2
    2 3 3
    3 4 4
    1 4 1
    1 5 5
    2 6 6
    3 7 7
    4 8 8
    
    Expected output
    15
    
  4. Example 4

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

    Input
    10 15
    6 8
    7 9
    2 7 12
    8 10 17
    1 3 1
    3 8 14
    5 7 15
    2 3 7
    1 10 14
    3 6 12
    1 5 10
    8 9 1
    2 9 7
    1 4 1
    1 8 1
    2 4 7
    5 6 16
    
    Expected output
    19