#P7098. [yLOI2020] 凉凉

    ID: 6135 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp2020O2优化状态压缩,状压

[yLOI2020] 凉凉

Description

This is the first problem in the yLOI series that is named after a song whose singer is not Yinlin. The song has little to do with the problem; it is just that our protagonist is called “Liangliang”, so Fusu chose this song for him.

After Liangliang met up in Qingdao with some friends from the group “Qijin in Chengdu drinking cold tea watching jk while cooing and quacking and chattering while clanking and chopping penguins on tiles”, he took the subway with Fusu and was seen off by Qijin to Qingdao North Railway Station. During the subway ride, they passed “Zuowuli Station (Cuobuling Station)”. Having just finished doing Gaokao physics, Liangliang asked Fusu, who did not want to do physics at all, a physics question. Fusu could not solve it, so Liangliang decided to test you with an economics problem.

Qingdao has nn subway lines and mm subway stations. The trains of each line run underground at a fixed depth. If a subway line at depth ii passes through station jj, then station jj must dig a platform at depth ii as the boarding/alighting access, and the cost of digging this access is ai,ja_{i,j}. We ignore the cost of building the passage from the access to the ground, and only consider the cost of building the access at that depth. Obviously, for lines uu and vv, if they both pass through the same station, then they cannot be at the same depth; otherwise, the two lines will collide. If uu and vv do not share any station, then they may be at the same depth or at different depths.

In this problem, you may assume that any two subways will not meet during travel except at stations; that is, you do not need to consider the case where two subways meet between two stations due to intersecting tracks.

Stations are numbered from 11 to mm, and lines are numbered from 11 to nn. You are now given the list of stations each of the nn lines passes through and the construction cost at each station for each depth. Please find the minimum total construction cost so that all subways can operate normally.

Input Format

The first line contains two integers, denoting the number of subway lines nn and the number of stations mm.
Lines 22 to (n+1)(n+1) each contain mm integers; the jj-th integer in line (i+1)(i+1) denotes ai,ja_{i,j}.
Lines (n+2)(n+2) to (2n+1)(2n+1) each contain several integers; line (n+i+1)(n+i+1) describes the route information of line ii:

Each line first contains an integer cc, denoting the number of stations this line passes through. Then the line contains cc distinct integers uu, in order, denoting the station numbers that this subway passes through.

Output Format

Output one line with one integer, the answer.

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

Hint

Sample 1 Explanation

Line 11 and line 22 both pass through station 11, so they cannot be at the same depth.
Let line 11 run at depth 22 and line 22 run at depth 11. Then we need to build the boarding/alighting accesses at station 11 for depths 11 and 22 (cost 4+4=84+4=8), the access at station 22 for depth 22 (cost 11), and the access at station 33 for depth 11 (cost 11), for a total cost of 1010. It can be proved that this is optimal.

Constraints

There are 2020 test points in total, each worth 55 points.

  • For 5%5\% of the testdata, it is guaranteed that n=1n=1.
  • For 35%35\% of the testdata, it is guaranteed that n,m6n,m \le 6.
  • For 70%70\% of the testdata, it is guaranteed that n10n \le 10.
  • For 100%100\% of the testdata, it is guaranteed that 1n141 \le n \le 14, 1m1051 \le m \le 10^5, 1ai,j1091 \le a_{i,j} \le 10^9, 1c,um1 \le c,u \le m.

Notes

This problem provides two additional sample files; see cold.zip in the attachments.

(There was originally a larger sample, but it was deleted because the attachment does not allow uploading such a large file.)

Translated by ChatGPT 5