其实就是检查第i 跟 i+1 序列是否合法
合法就不理它
如果不合法再变一下
最后再拓补检查一下构造出的解是否合法
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
#include <ctime>
#include <bitset>
using namespace std;
#define pb push_back
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define lans() printf("%lld",ans)
#define lanss() printf("%lld ",ans)
#define lansn() printf("%lld\n",ans)
#define fansn() printf("%.10f\n",ans)
#define r0(i,n) for(int i=0;i<(n);++i)
#define r1(i,e) for(int i=1;i<=e;++i)
#define rn(i,e) for(int i=e;i>=1;--i)
#define rsz(i,v) for(int i=0;i<(int)v.size();++i)
#define szz(x) ((int)x.size())
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define lowbit(a) (a&(-a))
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define mp(aa,bb) make_pair(aa,bb)
#define lrt rt<<1
#define rrt rt<<1|1
#define X first
#define Y second
#define PI (acos(-1.0))
#define sqr(a) ((a)*(a))
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1000000000+7;
const double eps=1e-9;
const int inf=0x3f3f3f3f;
const ll infl = 10000000000000000;
const int maxn= 100000+10;
const int maxm = 40000+10;
//Pretests passed
int in(int &ret)
{
char c;
int sgn ;
if(c=getchar(),c==EOF)return -1;
while(c!='-'&&(c<'0'||c>'9'))c=getchar();
sgn = (c=='-')?-1:1;
ret = (c=='-')?0:(c-'0');
while(c=getchar(),c>='0'&&c<='9')ret = ret*10+(c-'0');
ret *=sgn;
return 1;
}
vector<int>g[maxn],num[maxn];
bool error;
int c[maxn];
void dfs(int u)
{
int sz = g[u].size();
r0(i,sz)
{
int v = g[u][i];
if(c[v]==2)error =1;
else if (c[v]==0) c[v] = 1 , dfs(v);
}
}
int main()
{
#ifdef LOCAL
freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif // LOCAL
int n,m;
sdd(n,m);
r1(i,n)
{
int x;
sd(x);
while(x--)
{
int u;
sd(u);
num[i].pb(u);
}
}
r1(i,n-1)
{
int sz = num[i].size();
int sz2 = num[i+1].size();
int j = 0;
for(j = 0 ; j<sz&&j<sz2; ++j)if(num[i][j]!=num[i+1][j])break;
int a = num[i][j] , b = num[i+1][j];
if(j==sz2||j==sz)
{
if(sz>sz2)error = 1;
}
else if(a<b)g[b].pb(a);
else if(c[a]==2||c[b]==1)error = 1;
else c[a] =1 , c[b] = 2;
}
r1(i,m)
{
if(c[i]==1)dfs(i);
}
if(error)return 0*printf("No");
puts("Yes");
vector<int>o;
r1(i,m)if(c[i]==1)o.pb(i);
int ans = o.size();
ansn();
r0(i,ans)printf("%d ",o[i]);
return 0;
}