luogu#P9126. [USACO23FEB] Moo Route II S
[USACO23FEB] Moo Route II S
题目描述
Note: The time limit for this problem is 4s, twice the default.
Bessie is on vacation! Due to some recent technological advances, Bessie will travel via technologically sophisticated flights, which can even time travel. Furthermore, there are no issues if two "parallel" versions of Bessie ever meet.
In the country there are airports numbered and time-traveling flights . Flight leaves airport at time , and arrives in airport at time , is possible. In addition, she must leave time for a layover at airport . (That is to say, if Bessie takes a flight arriving in airport at time , she can then transfer to a flight leaving the airport at time if . The layovers do not affect when Bessie arrives at an airport.)
Bessie starts at city at time . For each airport from to , what is the earliest time when Bessie can get to at it?
输入格式
The first line of input contains and .
The next lines describe flights. The -th of these lines contains in that order.
The next line describes airports. It contains space separated integers, .
输出格式
There are lines of output. Line contains the earliest time when Bessie can get to airport , or if it is not possible for Bessie to get to that airport.
题目大意
题意
Bessie 正在旅游!有 个城市和 条航线,第 条航线有 $(c_i,r_i,d_i,s_i)(1\leq c_i, d_i\leq n,0\leq r_i,s_i\leq 10^9)$ 的限制,表示从 到 ,最迟 时进入, 时到达,注意 可能大于 。第 个城市有 的停泊时间,表示 乘坐航班到达 后,需要等待 的时间后才能继续飞行。问到达每个城市的最早时间?如果不能到达,输出 -1
。
Bessie 时刻在 城市。
输入格式
第一行两个整数 。
接下来 行每行四个整数 。
接下来一行 个整数,表示 。
输出格式
行,第 行一个整数表示到达 的最早时间,不能到达输出 -1
。
3 3
1 0 2 10
2 11 2 0
2 1 3 20
10 1 10
0
0
20
3 3
1 0 2 10
2 10 2 0
2 1 3 20
10 1 10
0
10
-1
提示
Explanation for Sample 1
Bessie can take the flights in the listed order, which allows her to arrive at airports and at time , and airport at time .
Note that this route passes through airport twice, first from time and then from time .
Explanation for Sample 2
In this case, Bessie can take flight , arriving at airport at time . However, she does not arrive in time to also take flight , since the departure time is and she cannot make a time-unit layover.
SCORING
- Inputs : for all , i.e. all flights arrive after they depart.
- Inputs :
- Inputs : No additional constraints.