QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#8743. 转化

الإحصائيات

题目描述

有 $n$ 种物品和 $m$ 种转化方式。第 $i$ 种转化方式可以将一个第 $a_i$ 种物品转化成 $k_i$ 个互不相同的物品,其中第 $j$ 个的种类是 $b_{i,j}$。同一种转化方式可以使用任意多次。

你有一些物品。你想知道,对于每一种特定的物品 $d$,你用这些你所拥有的物品可以分别转化出最多多少个该种物品。

输入格式

从标准输入读入数据。

第一行两个正整数 $n,m$。

第二行 $n$ 个非负整数,其中第 $i$ 个为 $c_i$,表示你拥有的第 $i$ 种物品的数量。

接下来 $m$ 行,其中第 $i$ 行表示第 $i$ 种转化方式。

转化方式的格式为:一行 $k_i+2$ 个正整数,其中第一个为 $a_i$,第二个为 $k_i$,之后为 $k_i$ 个互不相同的正整数 $b_{i,1},b_{i,2},\cdots,b_{i,k_i}$​​。

保证 $1\le n \le 100$,$1\le m \le 1000$。

保证 $1\le a_i,k_i,b_{i,j} \le n$。

保证 $0\le c_i \le 1000$。

输出格式

输出到标准输出。

输出 $n$ 行,其中第 $d$ 行表示第 $d$ 种物品最多能有多少个。如果可以任意多,即对于任意的 $N$ 都存在一种方案使得有超过 $N$ 个第 $d$ 种物品,输出 infinity

样例

输入

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

输出

1
1
1
2

解释

不使用任何转化方式,可以得到一个物品 $1$。

使用一次第一种转化方式,可以把物品 $1$ 变成物品 $2$ 和物品 $4$。这样可以得到一个物品 $2$。

使用一次第二种转化方式,可以把物品 $1$ 变成物品 $3$。这样可以得到一个物品 $3$。

使用一次第一种转化方式,可以把物品 $1$ 变成物品 $2$ 和物品 $4$。然后再使用一次第三种转化方式,可以把物品 $2$ 变成物品 $4$。这样可以得到两个物品 $4$。

可以证明这四种方案分别是当 $d=1,2,3,4$ 时的最优方案。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.