QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 256 MB 總分: 100

#8102. 商场

统计

Byton 被父母派往附近的购物中心购买清单上的 $m$ 种商品,商品编号为 $1$ 到 $m$。由于他热爱购物,他计划访问商场里的每一家商店,且每家商店恰好访问一次。Byton 将以某种顺序访问这些商店,并在其中一些商店购买他尚未购买的商品。

正如你所料,某些商品可能在多家不同的商店都有售。不幸的是,Byton 有点偏执——他非常害怕随机的安全检查。因此,他希望避免一种尴尬的情况:进入一家商店,而该商店出售他已经在别处购买过的商品。

你能找到一种访问所有商店并购买商品的策略,使 Byton 能够避免与保安发生尴尬的情况吗?

输入格式

输入的第一行包含两个整数 $n, m$ ($1 \le n, m \le 1000$),分别表示商场中商店的数量和 Byton 需要购买的商品数量。接下来的 $n$ 行描述了商场中的商店;第 $i$ 行描述第 $i$ 家商店。每行描述以一个数字 $k_i$ ($1 \le k_i \le m$) 开头,表示第 $i$ 家商店中 Byton 感兴趣的商品数量。随后是 $k_i$ 个整数,每个整数在 $1$ 到 $m$ 之间,按升序排列。每个整数代表 Byton 清单上的一种商品。

输出格式

如果不存在正确的购物策略,输出一个单词 NO。否则,第一行输出单词 YES。第二行输出 $n$ 个 $1$ 到 $n$ 之间的不同整数,表示 Byton 访问商店的顺序。第三行输出 $m$ 个 $1$ 到 $n$ 之间的整数,其中第 $i$ 个整数表示 Byton 应该在第几家商店购买商品 $i$。如果存在多种解,输出其中任意一种即可。

样例

输入 1

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

输出 1

YES
1 2 3 4
4 2 3 2

说明

首先,Byton 应该去商店 1,什么也不买。然后,他应该去商店 2 并购买商品 2 和 4。接下来,他可以在商店 3 购买商品 3,最后在商店 4 购买商品 1。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.