QOJ.ac

QOJ

时间限制: 0.6 s 内存限制: 512 MB 总分: 100

#4722. Norela

统计

第三代巫师王子 Adrian 在国际巫师日(11 月 4 日)想要给他的梦中情人 Norela 留下深刻印象。他有 $n$ 张扑克牌,初始时全部背面朝上放在桌子上。Adrian 可以使用 $m$ 个咒语,每个咒语的格式为:$q\ a_1\ a_2\ \dots\ a_q$。如果 Adrian 使用了一个咒语,那么索引为 $a_1, a_2, \dots, a_q$ 的牌将按顺序翻转(整数 $a_1, a_2, \dots, a_q$ 互不相同)。如果牌原本背面朝上,则会翻转为正面朝上;如果牌原本正面朝上,则会翻转为背面朝下。每个咒语最多只能使用一次。请帮助 Adrian 在他的宿敌 Manea Long Eyebrow 之前打动 Norela!

题目描述

找出使所有 $n$ 张牌正面朝上所需的最少咒语数量,并确定所使用咒语的索引。如果存在多种方案,请输出字典序最小的答案。

输入格式

第一行包含两个整数 $n$ 和 $m$。 接下来的 $m$ 行包含每个咒语的描述 $q\ a_1\ a_2\ \dots\ a_q$,其中 $q$ 是该咒语将翻转的牌的数量,$a_1, a_2, \dots, a_q$ 是这些牌的索引。

输出格式

第一行包含一个整数,表示所使用的最少咒语数量。 第二行包含所使用咒语的索引。如果存在多种使用最少咒语数量的方案,则输出字典序最小的方案。

子任务

  • 如果存在一个 $k$($1 \le k \le n$),使得 $a_1=b_1, a_2=b_2, \dots, a_{k-1}=b_{k-1}$ 且 $a_k < b_k$,则称整数集合 $a_1, a_2, \dots, a_n$ 在字典序上小于另一个集合 $b_1, b_2, \dots, b_n$。
子任务 分值 数据范围
1 20 分 $n \le 40, m \le 18$
2 30 分 $n \le 50, m \le 21$
3 25 分 $n \le 60, m \le 22$
4 25 分 $n \le 60, m \le 24$

样例

输入 1

5 6
3 1 3 4
2 3 5
2 2 3
3 1 2 5
1 1
4 1 2 3 4

输出 1

3
1 2 3

说明 1

使用索引为 1, 2 和 3 的咒语(分别对应 $1\ 3\ 4$,$3\ 5$ 和 $2\ 3$)可以将所有牌翻转为正面朝上。可以观察到,另一种使所有牌正面朝上的方案是 1, 4 和 5,但该方案的字典序更大。

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.