Skip to content

Commit

Permalink
Create level.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
mahaoming2022 authored Mar 30, 2024
1 parent a560992 commit fd45ac5
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions PJ/2013/level.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include<bits/stdc++.h>

using namespace std;

int n,m;
int a[1024],b[1024];
int linker[1023][1024];
int mem[1023];
bool vis[1024];

int dp(int u)
{
int& ans=mem[u];
if(ans!=-1)
return ans;
ans=0;
for(int v=1;v<=n;++v)
if(linker[u][v])
ans=max(ans,dp(v)+1);
return ans;
}

int main()
{
freopen("level.in","r",stdin);
cin>>n>>m;
for(int i=1;i<=m;++i)
{
memset(vis,0,sizeof(vis));
int si;
cin>>si;
for(int j=1;j<=si;j++)
{
cin>>a[j];
vis[a[j]]=1;
}
int ti=0;
for(int j=a[1];j<=a[si];++j)
if(!vis[j])
b[++ti]=j;
for(int u=1;u<=si;++u)
for(int v=1;v<=ti;++v)
linker[a[u]][b[v]]=1;
}
memset(mem,-1,sizeof(mem));
int ans=0;
for(int i=1;i<=n;++i)
ans=max(ans,dp(i));
cout<<ans+1;
}

0 comments on commit fd45ac5

Please sign in to comment.