Under construction

Still being built. Things may change

Don't Copy the Manga

Time limit1sMemory limit1024 MB

Summary
Given a weighted multigraph, find the tree on Hanbyeol's route from B to C that Toka can reach fastest from A, breaking ties by smallest number.
Level

Medium6 of 10

Topics
Graph, Shortest path, BFS
Solved
No attempts yet

Problem

Toka fell for the beautiful Hanbyeol senior she happened to run into! She wanted to talk to him but did not have the nerve, so she started looking for an excuse to speak to him. Toka reads a lot of manga, and in one comic she found a way to make that excuse. In the story, the male and female leads became friends after bumping into each other under cherry blossoms on the way to school. Toka decided to copy it.

Toka's neighborhood has no cherry trees, so she plans to try it at a place with ginkgo trees instead. Her neighborhood has NN ginkgo trees numbered from 11 to NN, and MM roads with a ginkgo tree at each end. Every road can be traveled in both directions, and any two ginkgo trees can always be reached from each other. Two different ginkgo trees may be connected by more than one road.

Hanbyeol likes open places. When he moves from one ginkgo tree to an adjacent one, he goes to the tree with the most roads connected to it. If several trees tie, he goes to the one with the largest number. Following only roads with many connections could make him circle the same roads forever, so he takes the route that passes through the fewest ginkgo trees on the way to school. Even if a tree has many roads, he does not head there if he cannot reduce the number of trees he passes through.

Toka wants to spend more time with Hanbyeol, so she plans to bump into him at the ginkgo tree on his route to school that she can reach from her house the fastest. If several trees tie, she will bump into him at the one with the smallest number. Since Toka is getting ahead of herself, you need to tell her the number of the ginkgo tree where she and Hanbyeol are fated to collide.

Input

The first line contains the number of ginkgo trees NN (3≤N≤100 0003 \le N \le 100\,000) and the number of roads MM (2≤M≤300 0002 \le M \le 300\,000), separated by a space.

The second line contains AA, the number of the ginkgo tree next to Toka's house, BB, the number of the ginkgo tree next to Hanbyeol's house, and CC, the number of the ginkgo tree next to the school, separated by spaces. (1≤A,B,C≤N1 \le A, B, C \le N; A≠BA \neq B; A≠CA \neq C; B≠CB \neq C)

From the third line onward, MM lines follow. Each line contains the numbers ii and jj of the ginkgo trees at the two ends of a road (1≤i,j≤N1 \le i, j \le N; i≠ji \neq j) and the time kk it takes to travel along the road (1≤k≤1091 \le k \le 10^9), separated by spaces.

Output

Print the number of the ginkgo tree where Toka must go to meet her fate.

Examples1

  1. Example 1

    Input
    10 12
    5 1 10
    1 3 6
    1 4 11
    2 3 7
    3 6 3
    3 7 8
    4 5 3
    4 7 5
    7 8 17
    7 9 6
    2 5 3
    10 9 13
    10 8 21
    
    Expected output
    7