#P1772. [ZJOI2006] 物流运输

    ID: 730 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp图论2006各省省选浙江NOI 导刊最短路

[ZJOI2006] 物流运输

Description

A logistics company needs to transport a batch of goods from port A to port B. Because the amount of goods is large, it will take nn days to finish. In general, the goods need to be transferred through several intermediate ports.

The company usually designs a fixed transportation route to enable strict management and tracking. Due to various factors, sometimes a port cannot load or unload cargo. In such cases, the route must be modified so that the goods can arrive on time.

However, changing the route is troublesome and incurs extra cost. Therefore, the company wants to make a transportation plan for nn days that minimizes the total cost.

On each day, you must choose a valid route from port A to port B that does not pass through any port that is unavailable on that day. Each time the route differs from the previous day’s route, an additional cost of kk is incurred. The transportation fee per unit length is 11. Ports are numbered from 11 to mm, where port A is 11 and port B is mm. All shipping routes are bidirectional. It is guaranteed that on every day there is at least one valid route from A to B.

The goal is to minimize the total cost, which equals the sum of the route lengths over nn days plus k×k \times the number of times the route is changed.

Input Format

The first line contains four integers n,m,k,en, m, k, e, where nn is the number of days, mm is the number of ports, kk is the cost of changing the route, and ee is the number of shipping routes.

Each of the next ee lines contains three integers u,v,wu, v, w, meaning there is a bidirectional shipping route between ports uu and vv with length ww. The transportation fee per unit length is 11. Port A is numbered 11, and port B is numbered mm.

The next line contains an integer dd. Each of the following dd lines contains three integers p,a,bp, a, b, meaning port pp is unavailable during days [a,b][a, b] (inclusive). The same port may be unavailable during multiple time intervals. For every day, there exists at least one route from port A to port B.

Output Format

Output a single integer: the minimal total cost.

The total cost is the sum of route lengths over nn days +k×+\, k \times the number of times the route is changed.

5 5 10 8
1 2 1
1 3 3
1 4 2
2 3 2
2 4 4
3 4 1
3 5 2
4 5 2
4
2 2 3
3 1 1
3 3 3
4 4 5

32

Hint

Constraints
For 100%100\% of the testdata, 1n1001 \le n \le 100, 1m201 \le m \le 20, 1k5001 \le k \le 500, 1e2001 \le e \le 200.

Sample Input Explanation

The figure shows the situations from day 11 to day 55; shaded ports are unavailable.

Sample Output Explanation

Use route 1451 \to 4 \to 5 for the first three days, and route 1351 \to 3 \to 5 for the last two days. Then the total cost is (2+2)×3+(3+2)×2+10=32(2+2) \times 3 + (3+2) \times 2 + 10 = 32.

Source: NOI Guide 2010 Senior (01).

Translated by ChatGPT 5