#P10544. [THUPC 2024 决赛] 转化

[THUPC 2024 决赛] 转化

Problem Description

There are nn types of items and mm types of transformations. The ii-th transformation can transform one item of type aia_i into kik_i pairwise distinct items, where the type of the jj-th item is bi,jb_{i,j}. The same transformation can be used any number of times.

You have some items. You want to know, for each specific item type dd, using the items you have, what is the maximum number of items of type dd that can be obtained through transformations.

Input Format

The first line contains two positive integers n,mn,m.

The second line contains nn non-negative integers, where the ii-th is cic_i, meaning the number of items of type ii that you have.

The next mm lines describe the transformations.
The format of a transformation is: one line with ki+2k_i+2 positive integers. The first is aia_i, the second is kik_i, followed by kik_i pairwise distinct positive integers bi,1,bi,2,,bi,kib_{i,1},b_{i,2},\cdots,b_{i,k_i}.

Constraints: 1n1001\le n \le 100, 1m10001\le m \le 1000.

It is guaranteed that 1ai,ki,bi,jn1\le a_i,k_i,b_{i,j} \le n.

It is guaranteed that 0ci10000\le c_i \le 1000.

Output Format

Output nn lines. The dd-th line should contain the maximum possible number of items of type dd. If it can be arbitrarily large, i.e., for any NN there exists a plan such that the number of items of type dd is greater than NN, output infinity.

4 4
1 0 0 0
1 2 2 4
1 1 3
2 1 4
3 1 4

1
1
1
2

Hint

Without using any transformation, you can obtain one item 11.

Using the first transformation once, you can turn item 11 into item 22 and item 44. In this way, you can obtain one item 22.

Using the second transformation once, you can turn item 11 into item 33. In this way, you can obtain one item 33.

Using the first transformation once, you can turn item 11 into item 22 and item 44. Then using the third transformation once, you can turn item 22 into item 44. In this way, you can obtain two items 44.

It can be proven that these four plans are optimal when d=1,2,3,4d=1,2,3,4, respectively.

Source and Acknowledgements

From the THUPC2024 Final (the 2024 Tsinghua University Student Programming Contest and Intercollegiate Invitational Contest). Thanks to THUSAA for providing this problem.

For the testdata, statement, reference solution, editorial, etc., please refer to the official THUPC repository: https://thusaac.com/public.

Translated by ChatGPT 5