#P14019. [ICPC 2024 Nanjing R] 地铁

[ICPC 2024 Nanjing R] 地铁

Description

In Pigeland, the subway system is quite advanced. It consists of nn sites, numbered from 11 to nn, and kk directed subway lines, numbered from 11 to kk. Subway line ii travels through sites xi,1,xi,2,,xi,pix_{i, 1}, x_{i, 2}, \cdots, x_{i, p_i} in order, where xi,jx_{i, j} is the jj-th site visited by line ii. It takes wi,jw_{i,j} units of time to travel from site xi,jx_{i,j} to site xi,j+1x_{i,j+1} on line ii.

When multiple lines meet at the same site, passengers can transfer between lines. If a passenger is at a site on line xx, while line yy also passes through this site, he/she can spend ay×bxa_y \times b_x units of time to transfer from line xx to line yy, where aya_y and bxb_x are given coefficients for lines yy and xx. After transferring, the passenger is still at the same site, but on line yy.

You start at site 11. Find the minimum time needed to reach site ss for all 2sn2 \le s \le n. In particular, you can start by choosing any line at site 11 with no transfer time cost. It is guaranteed that all sites are reachable from site 11.

Input Format

There is only one test case in each test file.

The first line contains two integers nn and kk (2n2×1052 \leq n \leq 2 \times 10^5, 1k2×1051 \leq k \leq 2 \times 10^5), indicating the number of sites and the number of subway lines.

The second line contains kk integers a1,a2,,aka_1, a_2, \cdots, a_k (1ai1061 \leq a_i \leq 10^6).

The third line contains kk integers b1,b2,,bkb_1, b_2, \cdots, b_k (1bi1061 \leq b_i \leq 10^6).

For the following kk lines, the ii-th line first contains an integer pip_i (2pin2 \leq p_i \leq n), indicating the number of sites line ii travels through. Then (2pi1)(2p_i - 1) integers $x_{i, 1}, w_{i, 1}, x_{i, 2}, \ldots, x_{i, p_i - 1}, w_{i, p_i - 1}, x_{i, p_i}$ follow (1xi,jn1 \leq x_{i,j} \leq n, 1wi,j1091 \leq w_{i,j} \leq 10^9), where xi,jx_{i, j} is the jj-th site visited by line ii, and wi,jw_{i,j} is the travel time from site xi,jx_{i,j} to site xi,j+1x_{i,j+1} on line ii. The sites traveled through by a subway line are distinct.

It is guaranteed that i=1k(pi1)2×105\sum\limits_{i=1}^k (p_i - 1) \leq 2 \times 10^5.

Output Format

Output one line containing (n1)(n - 1) integers d2,d3,,dnd_2, d_3, \cdots, d_n separated by a space, where did_i is the minimum time cost from site 11 to site ii.

6 3
1 5 1
5 5 1
3 1 2 2 3 3
3 5 1 2 1 4
3 3 4 5 4 6
2 5 21 14 18
6 3
1 5 1
5 5 1
5 1 2 2 100 3 100 6 1 4
5 1 100 2 4 3 100 5 1 4
2 3 1 5
2 31 43 37 136