Under construction

Still being built. Things may change

Evacuation

Time limit2sMemory limit1024 MB

Summary
Find the minimum time to send K cars from city 1 to city n over timed, capacitated one-way roads, or the fewest cars that miss the deadline T.
Level

Hard8 of 10

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

Problem

In TT minutes, the Chitauri army led by Loki attacks Earth. The Avengers cannot stop the portal from opening in New York in time, so Captain America has decided to evacuate all of the city's residents. He needs to find out whether the residents can leave the city before the invasion begins.

The area around New York can be viewed as a set of small cities connected by one-way roads. Each road has a length and a capacity. A length ll means that a car entering the road at time tt reaches its far end at time t+lt+l. A capacity ss means that at most ss cars can enter the road in any given minute. When a car reaches a city, it can immediately continue onto any road leaving that city, or it can stay in the city for any number of minutes before leaving.

Captain America has already chosen the city where New York's residents must be after the evacuation. He also knows how many cars are needed to evacuate the entire city. Now he must determine whether all residents can evacuate before the invaders arrive. If they can, find the minimum time they need. If they cannot, find the minimum number of cars carrying residents that will not reach the safe city.

Input

The first line contains four integers nn, mm, KK, and TT (1≤n×T≤10 0001 \le n \times T \le 10\,000, 1≤m,K≤10 0001 \le m, K \le 10\,000): the number of cities around New York, the number of roads between them, the number of cars that must travel from New York to the safe city, and the time until the invasion. The next mm lines describe the roads.

Each road is described by four integers uu, vv, ll, and ss (1≤u,v≤n1 \le u, v \le n, u≠vu \ne v, 1≤s≤3 0001 \le s \le 3\,000, 1≤l≤2001 \le l \le 200): the city the road leaves from, the city it leads to, its length, and its capacity.

There is at most one road between any two cities, and it goes in one direction only. New York is city 1, and the safe city is city nn. At time 0, all cars are in New York.

Output

If all residents can reach the safe city in no more than TT minutes, print the minimum number of minutes they need. Otherwise, print the minimum number of cars that cannot reach the safe city within TT minutes. You do not need to say which case applies.

Examples1

  1. Example 1

    Input
    5 5 10 10
    1 2 2 2
    2 3 1 1
    2 4 1 1
    4 5 2 4
    3 5 2 4
    
    Expected output
    9