A11176 | National Property
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line contains two integers $n$ and $m$ ( $2<=n<=100000$ , $1<=m<=100000$ ) — 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,li}$ ( $1<=l_{i}<=100000$ , $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 $100000$ .
Each of the next $n$ lines contains a description of one word in format $l_{i},s_{i,1},s_{i,2},...,s_{i,li}$ ( $1<=l_{i}<=100000$ , $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 $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.
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.
输入输出样例
输入 #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.
- $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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted