#P15184. [SWERC 2019] Environment-Friendly Travel

[SWERC 2019] Environment-Friendly Travel

题目描述

Taking holidays unfortunately has a carbon footprint. The CO₂-cost of a kilometer traveled depends on the mode of transportation. For instance, train travel is less costly than bus travel, which is itself less costly than car travel.

Your objective is to plan a holiday trip from your house, given by 2D coordinates (xs,ys)(x_s, y_s), to your travel destination, given by (xd,yd)(x_d, y_d). Being aware of the environmental impact of travel, you want to minimize the CO₂-cost of your holiday, but you still want to keep the total number of kilometers traveled within a given budget BB.

To aid you in planning, you have access to a map of NN stations, possibly linked by TT different modes of transportation (airplane, train, etc.) numbered 1,,T1, \ldots, T. Each mode has a CO₂-cost per distance unit C1,,CTC_1, \ldots, C_T. You can travel by car from your home to the destination, from your home to any station, and from any station to the destination point, at a cost C0C_0 per distance unit. C0C_0 is always greater than any of C1,,CTC_1, \ldots, C_T.

Each of the NN stations has coordinates (xi,yi)(x_i, y_i) for i=0,,N1i = 0, \ldots, N - 1. Each station may be connected to some other stations via one or several of the TT modes. Each connection works both ways, so only one direction has to be listed. There can be multiple modes of transportation available between two stations. You can only travel between two stations via their connections using the available transportation modes (car travel is not allowed between stations).

The distance between two points aa and bb is the 2D distance between (xa,ya)(x_a, y_a) and (xb,yb)(x_b, y_b), rounded to the nearest integer above:

$$\text{dist}(a, b) = \left\lceil \sqrt{(x_a - x_b)^2 + (y_a - y_b)^2} \right\rceil,$$

and the CO₂-cost of travel between aa and bb, using transport mode ii is:

$$\text{cost}(a, b, i) = C_i \times \text{dist}(a, b).$$

Given two source–destination coordinates, a budget BB expressed in distance units, a list of transportation modes and their respective CO₂-costs, and the station network, your task is to compute the minimal CO₂-cost possible while traveling at most BB kilometers.

输入格式

The input consists of the following lines:

  • Line 1 contains two space-separated integers, xsx_s and ysy_s, the coordinates of your house.
  • Line 2 contains two space-separated integers, xdx_d and ydy_d, the coordinates of your destination.
  • Line 3 contains an integer, BB, the maximal distance (in kilometers) that you accept to travel.
  • Line 4 contains an integer, C0C_0, the CO₂-cost per distance unit of traveling by car.
  • Line 5 contains an integer, TT, the number of modes of transportation (beside cars).
  • Line i+5i + 5, for 1iT1 \leq i \leq T, contains the integer CiC_i, the CO₂-cost per distance unit of transportation mode ii.
  • Line T+6T + 6 contains the integer NN, the number of stations.
  • Line i+T+7i + T + 7 describes station ii (0i<N0 \leq i < N) and contains 3+2×li3 + 2 \times l_i space-separated integers. The first three integers are xix_i, yiy_i and lil_i. The pair (xi,yi)(x_i, y_i) represents the coordinates of station ii, while lil_i is the number of links between station ii and other stations. The lil_i remaining pairs of integers (j,mj)(j, m_j) each describe a link to station jj (0j<N0 \leq j < N) using transportation mode mjm_j (1mjT1 \leq m_j \leq T). All links are bidirectional.

输出格式

The output should contain a single line with a single integer representing the minimal feasible CO₂-cost or 1-1 if no feasible cost is found within the kilometer budget.

1 1
10 2
12
100
2
10
50
3
2 3 2 1 1 2 2
5 5 1 2 1
9 3 0
850

提示

Sample Explanation

The results corresponds to the CO₂-cost of the following route:

  1. from home at (1,1)(1,1) to station 0 at (2,3)(2,3) by car for a cost of $100 \times \left\lceil \sqrt{1^2 + 2^2} \right\rceil = 300$,
  2. to station 2 at (9,3)(9,3) via transportation mode 2 for a cost of $50 \times \left\lceil \sqrt{7^2 + 0^2} \right\rceil = 350$,
  3. to the destination at (10,2)(10,2) by car for a cost of $100 \times \left\lceil \sqrt{1^2 + 1^2} \right\rceil = 200$ for a total of 850.

This route is valid because the total distance traveled is 3+7+2=123 + 7 + 2 = 12, within the allowed budget of 12.

Limits

All inputs are integers. All coordinates are in [0,100]×[0,100][0, 100] \times [0, 100].

  • 1T1001 \leq T \leq 100;
  • 1N10001 \leq N \leq 1000;
  • 0B1000 \leq B \leq 100;
  • 1C1,,CT<C01001 \leq C_1, \ldots, C_T < C_0 \leq 100;
  • for each station, there are at most 100 links to other stations.