Under construction

Still being built. Things may change

Driver's Dilemma

Interview

Time limit1sMemory limit1024 MB

Summary
Find the smallest maximum discomfort for a drive from district 1 to N within time T, where lowering a road's discomfort to D costs extra travel time.
Level

Medium6 of 10

Topics
Graph, Shortest path, Binary search
Solved
No attempts yet

Problem

A meeting was suddenly scheduled for an officer who had no plans. The officer's driver immediately opened a map to find the location of the meeting room.

The map has NN districts and MM roads connecting them in both directions. Each road has a travel time and a discomfort value. The driver starts in district 11, and the meeting room is in district NN.

The meeting is TT away, so the driver must reach the meeting room within time TT. The officer does paperwork in the car, so the driver must drive as smoothly as possible. The travel time to the meeting room is the sum of the travel times of the roads used. The discomfort the officer feels is the maximum discomfort among the roads used.

The driver can choose any road and lower its discomfort by xx by increasing its travel time by xx, where x>0x>0. Discomfort cannot go below 00. Driving too slowly to lower discomfort may cause the driver to miss the deadline, while driving at normal speed keeps discomfort high.

Find the minimum discomfort the officer feels when reaching the meeting room within time TT.

Input

The first line contains NN, MM, and TT separated by spaces. (2≤N≤50 0002\leq N\leq 50\,000, 1≤M≤100 0001\leq M\leq 100\,000, 1≤T≤1091\leq T\leq 10^9)

From the second line to the (M+1)(M+1)-th line, the ii-th line contains the two districts uiu_i and viv_i that road ii connects, followed by its travel time tit_i and discomfort sis_i, separated by spaces. (1≤ui,vi≤N1\leq u_i, v_i\leq N, ui≠viu_i\neq v_i, 1≤ti≤1091\leq t_i\leq 10^9, 0≤si≤1090\leq s_i\leq 10^9)

Output

Print the minimum discomfort the officer feels when reaching the meeting room within time TT.

If the meeting room cannot be reached within time TT in any way, print −1-1.

Examples2

  1. Example 1

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

    Input
    4 4 6
    1 2 3 4
    1 3 4 3
    3 4 3 2
    2 3 2 1
    
    Expected output
    -1