Jadonyzx @ 2024-09-19 09:44:59
暴力连边跑拓扑,应该是
#include<bits/stdc++.h>
#define maxn 1001
using namespace std;
int n,m,indgr[maxn],level[maxn],ans=1,s[maxn],up[maxn],down[maxn],topup,topdown;
bool edge[maxn][maxn];queue<int>q;
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m;
for(int i=1;i<=m;++i){
int len;cin>>len;topup=topdown=0;
for(int j=1;j<=len;++j)cin>>s[j];
int res=s[1];
for(int j=1;j<=len;++j){
up[++topup]=s[j];
if(s[j]-1>res)for(int k=res+1;k<s[j];++k)down[++topdown]=k;
res=s[j];
}
for(int j=1;j<=topup;++j){
for(int k=1;k<=topdown;++k){
if(!edge[down[k]][up[j]])indgr[up[j]]++;
edge[down[k]][up[j]]=1;
}
}
}
for(int i=1;i<=n;++i)level[i]=1;
for(int i=1;i<=n;++i)if(indgr[i]==0)q.push(i);
while(q.size()){
int now=q.front();q.pop();
for(int i=1;i<=n;++i){
int v=edge[now][i];
if(v)v=i;
else continue;
if(level[v]<=level[now])
level[v]=level[now]+1;
indgr[v]--;
if(indgr[v]==0)q.push(v);
}
}
for(int i=1;i<=n;++i)ans=max(ans,level[i]);
cout<<ans;
return 0;
}
by _chicken_ @ 2024-09-19 10:28:33
老noip特有的数据水?
by _liuyi_ @ 2024-09-19 11:57:38
@Jadonyzx 复杂度不是对的嘛,2e8凭啥不过啊
by Jadonyzx @ 2024-09-19 13:47:23
by lkjlkjlkj2012 @ 2024-09-28 11:20:08
一般洛谷评测机能4e8呢