#1354. [Baltic2005]Bus Trip

[Baltic2005]Bus Trip

题目描述

这里有 nn 座城镇,和城镇之间的 mm 条巴士单行线(没有中间停靠站),城镇从 11nn 标号。

一个旅行者在 00 时刻位于 11 号城镇想要到达 pp 号城镇。他将乘坐巴士在 tt 时刻到达 pp 号城镇,如果他早到了,他必须等待。

对于任意一个巴士路线 ii,我们知道其中的起点城镇 sis_i 和目标城镇 tit_i。我们也同样知道路线的出发时间和到达时间,但仅仅是近似值:我们知道巴士在时间范围 [ai,bi][a_i, b_i] 内离开起点城镇 sis_i,且在时间范围 [ci,di][c_i, d_i] 内到达目标城镇 tit_i(端点值包括在内)。

旅行者不喜欢等待,因此他要寻找一个旅行计划使得最大等待时间尽量小,同时保证绝对不会错过计划中的任何一辆巴士(意思是,每次他换乘巴士,他需要下车的巴士的最晚到达时间不会迟于他需要搭乘的下一辆巴士的最早出发时间)。

当计算等待时间时,我们必须假设最早可能到达的时间和最晚可能出发的时间。

编写一个程序,寻找一个最为合理的搭车计划。

输入格式

The input file name is TRIP.IN.

The first line contains the integer numbers n,m,pn,m,p , and tt .

The following mm lines describe the bus routes.

Each line contains the integer numbers si,ti,ai,bi,ci,dis_i, t_i, a_i, b_i, c_i, d_i, where sis_i and tit_i are the source and destination towns of the bus route ii, and ai,bi,ci,dia_i, b_i, c_i, d_i describe the departure and arrival times as explained above ).

输出格式

只需要包含一个数——最合理搭车方案的最长可能等待时间。

如果不可能保证在 tt 时刻到达城市 pp,那么输出 -1

3 6 2 100
1 3 10 20 30 40
3 2 32 35 95 95
1 1 1 1 7 8
1 3 8 8 9 9
2 2 98 98 99 99
1 2 0 0 99 101
32

数据规模与约定

对于 100%100\% 的数据,1n5×1041\leq n\leq 5\times 10^41m1041\leq m\leq 10^41pn1\leq p\leq n0t1090\leq t\leq 10^91si,tin1\leq s_i,t_i\leq n0aibi<cidi1090\leq a_i\leq b_i < c_i \leq d_i\leq 10^9