Description
All know this library of Bookland is the largest library in the world. There are dozens of thousands of the library.
Some long and uninteresting story was removed ...
The alphabet of Bookland is so large, its letters are denoted by positive. Each letter can be small or large and the large version of a letter x are denoted by X '. BSCII encoding, which is used everywhere in Bookland, are made in that way so this large letters the order The numbers they are denoted by, and small letters are presented into 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 x1, x2, ..., XA is not lexicographically greater than Y1, y2, ..., yb if one of the two following conditions B and x1 = y1, ..., xa = ya, i.e. the this is the prefix of second word;there is a position 1≤j≤min (a, b), Su ch that x1 = y1, ..., xj-1 = yj-1 and XJ < YJ, i.e. at the the ' the ' the ' position where the words differ the ' I word has a Smaller letter than the second word has.
For example, the word "3 ' 7 5" was before the word "2 4 ' 6" in lexicographical order. It is said this sequence of words is into lexicographical order if all word is not lexicographically greater the next Word in the sequence.
Denis has a sequence of words consisting a small only. He wants to some letters to large (let's call this process a capitalization) in such a way that sequence of wor DS is in lexicographical order. However, he soon realized the for some reason him can ' t change a single letter in a single word. He can choose a letter and the change all of it 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 him needs to-capitalize (make large) in order to make the sequence of words Lexicographi Cally ordered, or determine, it is impossible.
Note this some words can be equal.
Input
The contains two integers n and m (2≤n≤100 000, 1≤m≤100)-the number of words and the number of Le Tters 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's one word in format li, si, 1, si, 2, ..., Si, Li (1≤li≤100 000, 1≤s I, J≤m), where Li is the length of word, and Si, J are the sequence of letters in the word. The words are given in the order Denis has them in the sequence.
It is guaranteed this total length of ' all ' words is not greater than 100 000.
Output
In the ' the ' "Yes" (without quotes), if it is possible to capitalize some set of letters on 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 This 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.
examples Input
4 3
1 2 1 1 3 1 3 2 2 1-
1
examples Output
Yes
2
2 3
the
Now we want to sort the dictionary order of all the rows in ascending order, and for each number, we can use a transform, such as X->x ', all plus ' is not small, ask if you can find a transformation to make the original sequence ascending.
train of Thought
The original sequence is ascending as long as the adjacent two rows satisfy ascending order.
So we consider the adjacent two rows of A,b A,b, find the first Ai!=bi a_i!=b_i, then the size between the two sequences is determined by these two letters,
Since to ascending, if Ai<bi a_i, then already satisfies the ascending condition, chooses AI a_i then must select the Bi b_i, chooses B′i b_i ' then must choose A′i a_i ', Lian Bian ai−>bi,b′i−>a′i a_i->b _i,b_i '->a_i '.
If Ai>bi a_i>b_i, to make the original sequence ascending then must choose A′i,bi a_i ', B_i, Lian Bian ai−>a′i,b′i−>bi a_i->a_i ', B_i '->b_i.
Then apply the 2-sat template.
AC Code
#include <bits/stdc++.h>
#define IO Ios::sync_with_stdio (false); \
cin.tie (0); \
cout.tie (0)
; #define INF 0x7f7f7f7f
using namespace std;
typedef __int64 LL;
const int MAXN = 2E5+10;
const int MAXM = 4E5+10;
Class Twosat
{public
:
struct node
{
int to;
int next;
} EDGE[MAXM];
int Head[maxn],tot;
int LOW[MAXN],DFN[MAXN],STACK[MAXN],BELONG[MAXN],NUM[MAXN],TOPO[MAXN];
int index,top,sum;