六楼溜刘 @ 2022-10-25 10:29:41
rt
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1005;
int n,m,s,rd[N],a[N],ans,top;
bool vis[N],gt[N],e[N][N];
int read()
{
int m=0,n=1;
char ch;
ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
n=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
m=m*10+ch-'0';
ch=getchar();
}
return m*n;
}
signed main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
n=read();m=read();
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
gt[j]=false;
a[j]=0;
}
s=read();
for(int j=1;j<=s;j++){
a[j]=read();
gt[a[j]]=true;
}
for(int j=1;j<=s;j++){
for(int k=a[1];k<=a[s];k++){
if(!gt[k]&&!e[a[j]][k]){
e[a[j]][k]=true;
rd[k]++;
}
}
}
}
do{
top=0;
for(int i=1;i<=n;i++){
if(!rd[i]&&!vis[i]){
a[++top]=i;
vis[i]=true;
}
}
ans++;
for(int i=1;i<=top;i++){
for(int j=1;j<=n;j++){
if(e[a[i]][j]){
rd[j]--;
e[a[i]][j]=false;
}
}
}
}while(top>0);
printf("%d",ans-1);
}
有没有大佬帮帮忙,求求了Orz
by lzq066 @ 2022-10-25 10:35:49
qp