sczh @ 2019-11-23 09:24:57
#include<bits/stdc++.h>
#define MAX 10000005
using namespace std;
queue<int>q;
int n,m,_top,maxall,lrp[MAX],mvt[MAX],top_vis[MAX]
,to[MAX],next[MAX],fir[MAX],in[MAX];
void add_edge(int x,int y){
_top++;in[y]++;
to[_top]=y;next[_top]=fir[x];fir[x]=_top;
}
void top_delete(int x){
top_vis[x]=1;int t=fir[x];
while(t){in[to[t]]--;t=next[t];}
}
int main(){
int death=0;cin>>n>>m;
for(int i=1;i<=m;i++){
memset(lrp,0,sizeof(lrp));
int s;cin>>s;
for(int j=1;j<=s;j++){cin>>mvt[j];lrp[mvt[j]]=1;}
for(int j=1;j<=s;j++)
for(int k=mvt[1];k<=mvt[s];k++)
if(!lrp[k])
add_edge(k,mvt[j]);
}
for(;;){
for(int i=1;i<=n;i++)
if(!top_vis[i]&&!in[i])
q.push(i);
if(q.empty())break;
while(!q.empty()){top_delete(q.front());q.pop();}
death++;
}
cout<<death;
return 0;
}
求大佬为我指点迷津!
by ____蒟蒻____ @ 2019-11-23 10:19:42
指点迷津(×)
指点迷♂茎(√)
by ysmlwudia @ 2020-01-19 14:09:26
兄弟你是想n^3过1000吗?