This page is still under construction.

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

Mission

Time limit1sMemory limit1024 MB

Summary
In an undirected weighted graph, find the shortest simple path from B to H that passes through E.
Level

Medium7 of 10

Topics
Graph, Shortest path
Solved
No attempts yet

Problem

Attention, soldier.

I have a special task for you. We have detected an enemy base and it needs to be destroyed. You will be given a map and enough bombs to blow it up. After the action a helicopter will be waiting for you in the forest nearby.

Sounds easy, doesn't it? Find the fastest way to reach the goal, and make sure you do not visit any place twice. Visit a place twice and you will be detected.

Is everything clear? Very well. Get ready, because you are leaving in 10 minutes.

I wish you good luck. Don't get killed, and see you at dinner.

You are given an undirected graph and three different vertices of it: your base, the enemy base, and the place where the helicopter is waiting. Find the shortest path in the graph from your base to the helicopter's place. The path must go through the enemy base and must not visit any vertex twice.

Input

The first line contains five space separated integers NN, MM, BB, EE, HH.

The graph has NN vertices numbered 11 to NN. Your home base is at vertex BB, the enemy base at vertex EE, and the helicopter waits at vertex HH. It holds 1≤B,E,H≤N1 \le B, E, H \le N, and BB, EE, HH are pairwise different.

Each of the following MM lines describes one edge with three space separated integers vv, ww, tt (1≤v,w≤N1 \le v, w \le N, v≠wv \ne w, 1≤t≤10000001 \le t \le 1000000). It means there is an undirected edge connecting vertices vv and ww, and traversing it costs tt units of time.

No two vertices are connected by more than one edge.

It holds 3≤N≤10003 \le N \le 1000 and 0≤M≤10000 \le M \le 1000.

Output

Print a single line with a single integer, the least amount of time needed to complete the mission. If the mission cannot be completed, print -1 instead.

Examples3

  1. Example 1

    Input
    3 2 1 2 3
    1 2 10
    2 3 20
    
    Expected output
    30
    
  2. Example 2

    Input
    3 0 2 1 3
    
    Expected output
    -1
    
  3. Example 3

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