#P14019. [ICPC 2024 Nanjing R] 地铁
[ICPC 2024 Nanjing R] 地铁
Description
In Pigeland, the subway system is quite advanced. It consists of sites, numbered from to , and directed subway lines, numbered from to . Subway line travels through sites in order, where is the -th site visited by line . It takes units of time to travel from site to site on line .
When multiple lines meet at the same site, passengers can transfer between lines. If a passenger is at a site on line , while line also passes through this site, he/she can spend units of time to transfer from line to line , where and are given coefficients for lines and . After transferring, the passenger is still at the same site, but on line .
You start at site . Find the minimum time needed to reach site for all . In particular, you can start by choosing any line at site with no transfer time cost. It is guaranteed that all sites are reachable from site .
Input Format
There is only one test case in each test file.
The first line contains two integers and (, ), indicating the number of sites and the number of subway lines.
The second line contains integers ().
The third line contains integers ().
For the following lines, the -th line first contains an integer (), indicating the number of sites line travels through. Then 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 (, ), where is the -th site visited by line , and is the travel time from site to site on line . The sites traveled through by a subway line are distinct.
It is guaranteed that .
Output Format
Output one line containing integers separated by a space, where is the minimum time cost from site to site .
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
京公网安备 11011102002149号