CF875C.National Property
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You all know that the Library of Bookland is the largest library in the world. There are dozens of thousands of books in the library.
Some long and uninteresting story was removed...
The alphabet of Bookland is so large that its letters are denoted by positive integers. Each letter can be small or large, the large version of a letter x is denoted by x'. BSCII encoding, which is used everywhere in Bookland, is made in that way so that large letters are presented in the order of the numbers they are denoted by, and small letters are presented in the order of the numbers they are denoted by, but all large letters are before all small letters. For example, the following conditions hold: 2 < 3, 2' < 3', 3' < 2.
A word _x_1, _x_2, ..., x__a is not lexicographically greater than _y_1, _y_2, ..., y__b if one of the two following conditions holds:
- a ≤ b and _x_1 = _y_1, ..., x__a = y__a, i.e. the first word is the prefix of the second word;
- there is a position 1 ≤ j ≤ min(a, b), such that _x_1 = _y_1, ..., x__j - 1 = y__j - 1 and x__j < y__j, i.e. at the first position where the words differ the first word has a smaller letter than the second word has.
For example, the word "3' 7 5" is before the word "2 4' 6" in lexicographical order. It is said that sequence of words is in lexicographical order if each word is not lexicographically greater than the next word in the sequence.
Denis has a sequence of words consisting of small letters only. He wants to change some letters to large (let's call this process a capitalization) in such a way that the sequence of words is in lexicographical order. However, he soon realized that for some reason he can't change a single letter in a single word. He only can choose a letter and change all of its occurrences in all words to large letters. He can perform this operation any number of times with arbitrary letters of Bookland's alphabet.
Help Denis to choose which letters he needs to capitalize (make large) in order to make the sequence of words lexicographically ordered, or determine that it is impossible.
Note that some words can be equal.
众所周知,书之国(Bookland)的图书馆是世界上最大的图书馆,馆内藏书数以万计。
一段冗长而乏味的故事已被删去……
书之国的字母表极为庞大,其字母用正整数表示。每个字母可分为小写或大写形式;字母 x 的大写形式记作 x′。书之国普遍采用的 BSCII 编码规则如下:所有大写字母按其所对应数字的大小升序排列,所有小写字母也按其所对应数字的大小升序排列,但所有大写字母均排在所有小写字母之前。例如,以下关系成立:2<3,2′<3′,3′<2。
设单词 x1,x2,…,xa 字典序不大于 单词 y1,y2,…,yb,当且仅当满足以下两个条件之一:
- a≤b 且 x1=y1,…,xa=ya,即第一个单词是第二个单词的前缀;
- 存在位置 1≤j≤min(a,b),使得 x1=y1,…,xj−1=yj−1,且 xj<yj,即在两单词首次出现差异的位置上,第一个单词的字母严格小于第二个单词的对应字母。
例如,单词 “3′ 7 5” 在字典序上位于单词 “2 4′ 6” 之前。若一个单词序列中每个单词都不字典序大于其后继单词,则称该序列是字典序有序的。
丹尼斯拥有一组仅含小写字母的单词序列。他希望将其中某些字母改为大写(我们称此操作为“大写化”),使得整个单词序列变为字典序有序。然而,他很快意识到:出于某种原因,他无法单独修改某个单词中的某一个字母。他唯一能做的,是选定某个字母,并将该字母在所有单词中所有出现位置全部改为大写形式。他可以对书之国字母表中的任意字母执行该操作任意多次。
请帮助丹尼斯确定:应将哪些字母大写化,才能使单词序列变为字典序有序;或者判断该任务不可能完成。
注意:序列中可能存在相等的单词。
输入格式
The first line contains two integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — the number of words and the number of letters in Bookland's alphabet, respectively. The letters of Bookland's alphabet are denoted by integers from 1 to m.
Each of the next n lines contains a description of one word in format l__i, s__i, 1, s__i, 2, ..., s__i, l__i (1 ≤ l__i ≤ 100 000, 1 ≤ s__i, j ≤ m), where l__i is the length of the word, and s__i, j is the sequence of letters in the word. The words are given in the order Denis has them in the sequence.
It is guaranteed that the total length of all words is not greater than 100 000.
第一行包含两个整数 n 和 m(2≤n≤100000,1≤m≤100000),分别表示单词个数以及 Bookland 字母表中的字母个数。Bookland 字母表中的字母用 1 到 m 的整数表示。
接下来的 n 行中,每行描述一个单词,格式为 li, si,1, si,2, …, si,li(其中 1≤li≤100000,1≤si,j≤m),其中 li 表示该单词的长度,si,j 表示该单词中第 j 个字母。这些单词按 Denis 序列中的顺序给出。
保证所有单词的总长度不超过 100000。
输出格式
In the first line print "Yes" (without quotes), if it is possible to capitalize some set of letters in such a way that the sequence of words becomes lexicographically ordered. Otherwise, print "No" (without quotes).
If the required is possible, in the second line print k — the number of letters Denis has to capitalize (make large), and in the third line print k distinct integers — these letters. Note that you don't need to minimize the value k.
You can print the letters in any order. If there are multiple answers, print any of them.
第一行输出“Yes”(不带引号),表示是否存在一种方式,通过将某些字母大写,使得单词序列变为字典序升序;否则输出“No”(不带引号)。
若存在满足要求的方式,则在第二行输出 k —— Denis 需要大写(即转为大写)的字母个数;第三行输出 k 个互不相同的整数 —— 这些字母的编号。注意:你不需要使 k 最小。
字母可以按任意顺序输出。若存在多种答案,输出任意一种即可。
输入输出样例
输入#1
4 3 1 2 1 1 3 1 3 2 2 1 1
输出#1
Yes 2 2 3
输入#2
6 5 2 1 2 2 1 2 3 1 2 3 2 1 5 2 4 4 2 4 4
输出#2
Yes 0
输入#3
4 3 4 3 2 2 1 3 1 1 3 3 2 3 3 2 3 1
输出#3
No
说明/提示
In the first example after Denis makes letters 2 and 3 large, the sequence looks like the following:
- 2'
- 1
- 1 3' 2'
- 1 1
The condition 2' < 1 holds, so the first word is not lexicographically larger than the second word. The second word is the prefix of the third word, so the are in lexicographical order. As the first letters of the third and the fourth words are the same, and 3' < 1, then the third word is not lexicographically larger than the fourth word.
In the second example the words are in lexicographical order from the beginning, so Denis can do nothing.
In the third example there is no set of letters such that if Denis capitalizes them, the sequence becomes lexicographically ordered.
在第一个例子中,Denis 将第 2 和第 3 个字母变为大写后,序列如下所示:
- 2'
- 1
- 1 3' 2'
- 1 1
条件 2′ < 1 成立,因此第一个单词并不按字典序大于第二个单词。第二个单词是第三个单词的前缀,因此它们满足字典序关系。由于第三个和第四个单词的首字母相同,且 3′ < 1,因此第三个单词并不按字典序大于第四个单词。
在第二个例子中,这些单词从一开始就是按字典序排列的,因此 Denis 无需进行任何操作。
在第三个例子中,不存在任何一组字母,使得 Denis 将其变为大写后,整个序列变为按字典序排列。
输入解题思路,AI测评打分。不知道怎么写?