Xie_BR @ 2019-05-24 15:12:57
凭啥我的代码T了???!!!
#include<bits/stdc++.h>
#define MK 1500
using namespace std;
int n,m;
int s[MK][MK];
int flag[MK][MK];
int indegree[MK];
int mp[MK][MK];
int ans;
int add(int x,int y)
{
if(mp[x][y]==1)
{
return 0;
}
mp[x][y] = 1;
indegree[y]++;
return 0;
}
int dis[MK];
int topsort()
{
queue<int>qu;
for(int i=1;i<=n;i++)
{
if(indegree[i]==0)
{
qu.push(i);
dis[i] = 1;
ans = 1;
}
}
while(!qu.empty())
{
int f = qu.front();
qu.pop();
for(int i=1;i<=n;i++)
{
if(mp[f][i]==0)
{
continue;
}
int to = i;
indegree[to]--;
ans = max(dis[to],dis[f]+1);
dis[to] = dis[f]+1;
if(indegree[to]==0)
{
qu.push(to);
}
}
}
return 0;
}
signed main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
int x;
int y;
scanf("%d",&x);
for(int j=1;j<=x;j++)
{
scanf("%d",&y);
s[i][j] = y;
flag[i][y] = 1;
}
for(int j=1;j<=x;j++)
{
for(int k=s[i][1];k<=s[i][x];k++)
{
if(flag[i][k]==1)
{
continue;
}
add(s[i][j],k);
}
}
}
topsort();
printf("%d",ans);
return 0;
}
by ycyaw @ 2019-05-24 16:02:35
@Xie_BR 凭你不开O2
by Xie_BR @ 2019-05-25 14:24:46
@ιχγббб 我吸了很多次氧了,没有用。。。