求大佬帮看

P1983 [NOIP2013 普及组] 车站分级

JerryCao @ 2016-09-20 19:23:26

#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = 1000+10;
const int maxm = maxn*maxn;
queue<int> Q;
int IND[maxn],A[maxn][maxn],X[maxn],D[maxn],V[maxn];
int n,ans = 0;
void tpst()
{
    for (int i = 1; i<=n; i++)
    if (!IND[i])
    {
        Q.push(i);
        D[i] = 1;
    }
    while (!Q.empty())
    {
        int x = Q.front();
        Q.pop();
        for (int i = 1; i<=n; i++)
        {
            if (A[x,i])
            {
                IND[i]--;
                if (!IND[i])
                {
                    D[i] = max(D[x]+1,D[i]);
                    Q.push(i);
                    if (D[i]>ans) ans = D[i];
                }
            }
        }
    }
    return;
}
int main()
{
    int m;
    scanf("%d%d",&n,&m);
    memset(IND,0,sizeof(IND));
    memset(A,0,sizeof(A));
    memset(X,0,sizeof(X));
    memset(D,0,sizeof(D));
    memset(V,0,sizeof(V));
    for (int mm,i = 1; i<=m; i++)
    {
        scanf("%d",&mm);
        for (int x,j = 1; j<=mm; j++)
        {
            scanf("%d",&x);
            X[j] = x;
            V[x] = 1;
        }
        int a = X[1];
        for (int b,j = 2; j<=mm; j++)
        {
            b = X[j];
            for (int k = a+1; k<=b-1; k++)
            {
                if (!V[k])
                for (int l = 1; l<=mm; l++)
                {
                    if (!A[k][X[l]])
                    {
                        A[k][X[l]] = 1;
                        IND[X[l]]++;
                    }
                }
            }
            a = b;
        }
    }
    tpst();
    printf("%d\n",ans);
    return 0;
}

|