Traffic Lights
题号:NC273395
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

The road construction in City A consists of n intersections with traffic lights (numbered from 0 to n - 1) and m bidirectional roads.

Here are the rules:

1. All vehicles travel at maximum speed.
2. Starting from 0 seconds, traffic lights at all intersections alternate between green, yellow, and red signals. When a vehicle arrives, it can pass if the light is green or yellow; otherwise, it must stop immediately. Specifically, if the light turns green at the moment of arrival, vehicles can pass. If the light turns red at the moment of arrival, vehicles cannot pass.
3. Each intersection's traffic light has three parameters g, y, r, representing the durations of green, yellow, and red lights, respectively. The transition of traffic lights does not consume time.
4. It takes 5 seconds for a vehicle to accelerate from a standstill to maximum speed. During this period, the vehicle's speed is 0. The transition of traffic lights during the acceleration process is not considered.

If a vehicle departs from intersection s at time 0, the task is to find the shortest time to reach intersection e. It is guaranteed that any two intersections in City A can be reached through roads.

输入描述:

The first line contains four integers n, m, s, e, with the constraints 1 \le n \le 10^4, 1 \le m \le 2 * 10^4, 0 \le s, e \le n - 1, s \neq e.
Following that, there are n lines, each with three integers g_i, y_i, r_i, representing the three parameters of traffic lights at intersection i (where intersections are numbered from 0 to n - 1). It's guaranteed that 1 \le g_i, y_i, r_i \le 100, and g_i + y_i \ge 5.
Then, there are m lines, each with l_1, l_2, t, describing a road between intersections l_1 and l_2 with a transit time of t. Note that this time does not include the startup time; in other words, the total time including startup and transit is 5+t. Roads are bidirectional, and it's guaranteed that 0 \le l_1, l_2 \le n - 1, l_1 \neq l_2, and 1 \le t \le 500.
Multiple test cases are expected, with the end indicated by n = m = s = e = 0. Each test case set contains at most 10 test cases.

输出描述:

For each dataset, output a line in the format A:B indicating the required time as A minutes and B seconds. If B is less than or equal to 9, add a leading zero to B.
示例1

输入

复制
3 3 0 2
3 4 5
3 3 3
2 4 4
0 1 1
1 2 2
0 2 12
3 3 0 2
3 4 5
3 4 3
2 4 4
0 1 1
1 2 2
0 2 12
0 0 0 0

输出

复制
0:16
0:08