Under construction

Still being built. Things may change

Jogging

Time limit3sMemory limit512 MB

Summary
Find the maximum number of days Pheobe can run, where each run starts and ends at home, has length between L and U meters, and uses a street segment not used before.
Level

Medium7 of 10

Topics
Graph, Shortest path, DFS
Solved
No attempts yet

Problem

Pheobe has heard that exercise has a tremendous effect on both physical and mental health. She has never gone jogging before, and she wants to try it. However, she gets bored quickly and finds it hard to repeat the same thing. To build a jogging habit, Pheobe takes on a challenge: she will go out for a run every evening as long as she can find an interesting path. A path is interesting if it goes through a street she has not run on before. Help Pheobe find the maximum number of days she can run if she plans well.

Pheobe gives you a description of her neighborhood. She lives at an intersection, and she describes all intersections in the neighborhood. She also tells you which intersections are connected by streets and the length of each street in meters. Every street connects two different intersections, and no two different streets connect the same pair of intersections. You may assume that Pheobe only describes streets reachable from her home, and that streets can be traversed in both directions because Pheobe travels on foot.

A valid run starts and ends at Pheobe's home, and its length must be within the range she specifies. When Pheobe enters a street, she does not have to go through the entire street. She can turn around at any point, but even then, the street counts as fully seen for the purpose of determining whether runs are interesting. A run is interesting if it includes a street (or a segment of one) that did not appear on any previous run. Reaching an intersection does not count as visiting all streets adjacent to it.

Input

The first line contains four space-separated integers II SS LL UU. II is the number of intersections, and SS is the number of streets. LL is the minimum length in meters of a valid run, and UU is the maximum length in meters of a valid run.

Each of the next SS lines describes a street with three space-separated integers ii jj ℓ\ell. Streets ii and jj are the intersections the street connects, and ℓ\ell is the length of the street in meters. Intersections are numbered from 00 to I−1I-1, and Pheobe lives at intersection 00.

Output

Print a single line containing one integer: the length of the longest sequence of interesting runs.

Constraints

  • 1≤I≤100 0001 \le I \le 100\,000
  • 0≤S≤100 0000 \le S \le 100\,000
  • 1≤L≤U≤42 1951 \le L \le U \le 42\,195 (Pheobe will not run more than a marathon)
  • 1≤ℓ≤1 0001 \le \ell \le 1\,000

Examples2

  1. Example 1

    Input
    4 4 80 90
    0 1 40
    0 2 50
    1 2 30
    2 3 10
    
    Expected output
    3
    
  2. Example 2

    Input
    2 1 7 7
    0 1 3
    
    Expected output
    1