SIRO Challenge
Time limit8sMemory limit512 MB
Jiro starts at station s, visits as many of up to 16 ramen stations as possible, and returns within time t, paying rail travel plus eating time.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Shortest path, Graph, Bit manipulation
- Solved
- No attempts yet
Problem
You and your friend Jiro are at a summer training camp for programming contests. Jiro is a devoted fan of the ramen chain SIRO. Every SIRO restaurant serves its own ramen, so he wants to eat at as many different restaurants as he can tonight. His time is short, because he has to get up early tomorrow for a training session. He asked you to find the largest number of different restaurants he can reach and eat at within the time he has.
The city has railway stations, numbered through . Station is the closest one to the camp venue. pairs of stations are directly connected by railway: you move between station and station in minutes, in either direction. There is a SIRO restaurant near of the stations. At most one SIRO restaurant is near any single station, and no restaurant is near station . Jiro takes minutes to eat ramen at the restaurant near station .
Walking between a station and the restaurant near it takes a negligibly short time. Assume also that Jiro never waits for his ramen to be served.
Jiro is at station now and has to come back to that station within minutes. How many different SIRO restaurants can he taste?
Input
The input is a sequence of datasets. The number of datasets does not exceed . Each dataset has this format.
n m l s t
a1 b1 c1
:
:
am bm cm
j1 e1
:
:
jl el
The first line of each dataset holds five integers.
-
, the number of stations
-
, the number of directly connected pairs of stations
-
, the number of SIRO restaurants
-
, the starting station
-
, the time limit for Jiro
Each of the next lines holds three integers.
-
and , the two connected stations
-
, the time it takes to move between those two stations
Each of the next lines holds two integers.
-
, the station a SIRO restaurant is near
-
, the time Jiro takes to eat at that restaurant
The end of the input is a line with five zeros. That line is not a dataset.
Every dataset satisfies these constraints.
-
-
-
-
-
-
-
-
-
-
-
The are all distinct.
-
-
and for every
Some stations may be unreachable from the starting point .
Output
For each dataset, print on its own line the largest number of different restaurants Jiro can go to within the time limit.