This page is still under construction.

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

Delivering Rice Cakes

Interview

Time limit1sMemory limit512 MB

Summary
Given a weighted graph, a start house Y, and a daily walking limit X, find how many days it takes to visit every other house if each day's trip must return to Y and stay within X.
Level

Medium6 of 10

Topics
Graph, Shortest path, Greedy, Sorting
Solved
No attempts yet

Problem

Seonghyeon, a soldier, moved into a new house after being discharged. Wanting to get along with the neighbors, he decided to deliver rice cakes to the neighboring houses. He can carry only one rice cake at a time. There are M bidirectional roads between the houses in total.

Seonghyeon finds this tiresome, so he does not walk more than X per day and visits the closest houses first. He also insists on sleeping at his own house, so he resolves to visit any house he cannot make a round trip to on the next day. What is the minimum number of days needed to deliver rice cakes to all N-1 neighboring houses?

The houses are numbered 0 through N-1 in order.

Input

The first line gives N, M, X, Y separated by spaces. (2 ≤ N ≤ 1,000, 1 ≤ M ≤ 100,000, 1 ≤ X ≤ 10,000,000, 0 ≤ Y < N)

From the second line to the M+1-th line, A, B, and the length C of the road between house A and house B are given. (0 ≤ A,B < N, 1 ≤ C ≤ 10,000) A and B are distinct, and C is an integer.

The road connecting house A and house B is unique.

Output

Given that Seonghyeon's house is Y, print the minimum number of days needed to deliver rice cakes to all the neighboring houses. If he cannot visit them all, print -1.

Examples2

  1. Example 1

    Input
    5 6 21 0
    0 1 6
    0 2 3
    0 3 10
    1 2 2
    2 4 7
    3 4 8
    
    Expected output
    3
    
  2. Example 2

    Input
    6 5 10 4
    0 4 6
    0 5 2
    1 3 1
    1 5 8
    2 3 1
    
    Expected output
    -1