#P94. [NOI 2025 Day 1] 机器人

[NOI 2025 Day 1] 机器人

Person in Charge

Problem Description

NOI2025 is being held in Shaoxing, and Little Y has built a robot for the closing ceremony performance and plans to control it to move from the warehouse to the auditorium.

The road system in Shaoxing can be simplified as nn intersections and mm one-way roads connecting these intersections, each with a certain length. To facilitate the input of the road system into the robot's chip, Little Y has numbered all the roads originating from each intersection. Specifically, if there are dd roads starting from intersection xx, these dd roads will be numbered by Little Y in some order as 1d1 \sim d, referred to as the 1st1^{st} to dthd^{th} roads starting from xx.

Little Y's robot has an internal parameter pp. Given the upper limit kk of the parameter pp and the modification costs v1,v2,,vk1,w2,w3,,wkv_1, v_2, \ldots, v_{k-1}, w_2, w_3, \ldots, w_k, Little Y will set and modify the robot's parameter according to the following rules:

  • Initially, Little Y sets the parameter pp to 11.
  • At any time, Little Y can remotely control the robot to modify the parameter:
    • If p<kp < k, Little Y can spend vpv_p to increase pp by 11, i.e., pp+1p \leftarrow p + 1;
    • If p>1p > 1, Little Y can spend wpw_p to decrease pp by 11, i.e., pp1p \leftarrow p - 1.

Initially, Little Y's robot is located at the robot warehouse, which is intersection 11. When the robot is at intersection xx, let the pthp^{th} road starting from intersection xx have destination yy and length zz. Then, Little Y can spend zz to control the robot to move from xx to yy. Specifically, if there are fewer than pp roads starting from intersection xx, Little Y cannot control the robot to move.

Little Y does not know which intersection the auditorium for the closing ceremony is located at, so he needs to prepare for every intersection. Please help him determine the minimum cost required to move the robot from the warehouse to each intersection.

Input Format

The first line of input contains a non-negative integer cc, representing the test case number. c=0c = 0 indicates that the test case is a sample.

The second line of input contains three positive integers n,m,kn, m, k, representing the number of intersections, the number of roads, and the upper limit of the parameter pp.

The third line of input contains k1k - 1 non-negative integers v1,,vk1v_1, \ldots, v_{k-1}, representing the costs to increase the parameter pp.

The fourth line of input contains k1k - 1 non-negative integers w2,,wkw_2, \ldots, w_k, representing the costs to decrease the parameter pp.

The (i+4)th(i + 4)^{th} line of input (for 1in1 \le i \le n) contains several positive integers. The first non-negative integer did_i represents the number of roads starting from intersection ii, followed by 2di2d_i positive integers $y_{i,1}, z_{i,1}, y_{i,2}, z_{i,2}, \ldots, y_{i,d_i}, z_{i,d_i}$, representing the roads starting from intersection ii, where yi,j,zi,jy_{i,j}, z_{i,j} (for 1jdi1 \le j \le d_i) represent the destination and length of the jthj^{th} road, respectively.

Output Format

Output one line containing nn integers, where the ithi^{th} integer (for 1in1 \le i \le n) represents the minimum cost required for Little Y to move the robot from the warehouse to intersection ii. Specifically, if the robot cannot be moved to the intersection, output 1-1.

Samples

0
5 6 3
2 4
1 1
3 2 5 3 1 4 2
1 3 2
2 1 2 4 1
0
0
0 5 3 4 -1

Sample 1 Explanation

Little Y can use the following plans to move the robot from the warehouse to intersections 141 \sim 4:

  • For intersection 11: The robot is initially at intersection 11, so the cost is 00.
  • For intersection 22: Little Y controls the robot to move along the 1st1^{st} road starting from intersection 11 to intersection 22, with a cost of 55.
  • For intersection 33: Little Y increases the parameter pp by 11, then controls the robot to move along the 2nd2^{nd} road starting from intersection 11 to intersection 33, with a cost of 2+1=32 + 1 = 3.
  • For intersection 44: Little Y increases the parameter pp by 11, then controls the robot to move along the 2nd2^{nd} road starting from intersection 11 to intersection 33, and then moves along the 2nd2^{nd} road starting from intersection 33 to intersection 44, with a cost of 2+1+1=42 + 1 + 1 = 4.

It can be proven that the costs of the above plans are all minimal.

  • For intersection 55: Since Little Y cannot move the robot to intersection 55, the output is 1-1.

Sample 2

See the files robot/robot2.in and robot/robot2.ans in the contestant directory.

This sample satisfies the constraints of test cases 353 \sim 5.

Sample 3

See the files robot/robot3.in and robot/robot3.ans in the contestant directory.

This sample satisfies the constraints of test cases 686 \sim 8.

Sample 4

See the files robot/robot4.in and robot/robot4.ans in the contestant directory.

This sample satisfies the constraints of test cases 9,109, 10.

Sample 5

See the files robot/robot5.in and robot/robot5.ans in the contestant directory.

This sample satisfies the constraints of test cases 161816 \sim 18.

Data Range

For all test data, the following guarantees hold:

  • 1n,m3×1051 \le n, m \le 3 \times 10^5, 1k2.5×1051 \le k \le 2.5 \times 10^5;
  • For all 1ik11 \le i \le k - 1, 0vi1090 \le v_i \le 10^9;
  • For all 2ik2 \le i \le k, 0wi1090 \le w_i \le 10^9;
  • For all 1in1 \le i \le n, 0dik0 \le d_i \le k, and i=1ndi=m\sum_{i=1}^{n} d_i = m;
  • For all 1in1 \le i \le n, 1jdi1 \le j \le d_i, 1yi,jn1 \le y_{i,j} \le n, 1zi,j1091 \le z_{i,j} \le 10^9.
Test Case n,mn, m \le kk \le Special Properties
1,21, 2 66 C
353 \sim 5 10310^3
686 \sim 8 5×1045 \times 10^4 10210^2 None
9,109, 10 10510^5 AB
11,1211, 12 A
131513 \sim 15 C
161816 \sim 18 None
19,2019, 20 3×1053 \times 10^5 2.5×1052.5 \times 10^5
  • Special Property A: v1=v2==vk1=0v_1 = v_2 = \cdots = v_{k-1} = 0 and w2=w3==wk=0w_2 = w_3 = \cdots = w_k = 0.
  • Special Property B: For all 1in1 \le i \le n, 1jdi1 \le j \le d_i, zi,j=1z_{i,j} = 1.
  • Special Property C: At most 1010 intersections ii satisfy di10d_i \ge 10.