why RE

P1983 [NOIP2013 普及组] 车站分级

WZWZWZWY @ 2023-08-12 19:41:22

寄录

#include <iostream>

#include <queue>

using namespace std;

int s,a[1005],x[1005];

int in[1005],depth[1005];

int nxt[1000005],head[1000005],to[1000005],cnt=-1;

void add(int u, int v) {

    nxt[++cnt] = head[u];  // 当前边的后继

    head[u] = cnt;         // 起点 u 的第一条边

    to[cnt] = v;           // 当前边的终点

}

queue<int> q;

int main(){

    int n,m;

    cin >> n >> m;

    for (int i = 1; i <= n; i++) head[i] = -1;

    for (int i = 1; i <= m; i++) {

        for (int j = 1; j <= n; j++) a[j] = 0;

        cin >> s;

        for (int j = 1; j <= s; j++){

            cin >> x[j];

            a[x[j]] = 1;

        }

        for (int j = 1; j <= s; j++){

            for (int k = x[1]; k <= x[s]; k++){

                if (!a[k]) {

                    add(x[j],k);

                    in[k]++;

                }

            }

        }

    }

    for (int i = 1; i <= n; i++){

        if (!in[i]) {

            q.push(i);

            depth[i] = 1;

        }

    }

    while(q.size()){

        int u = q.front();

        q.pop();

        for (int i = head[u]; i != -1; i = nxt[i]){

            int v = to[i];

//          depth[v] = max(depth[v],depth[u]+1);

            in[v]--;

            if (in[v] == 0){

                q.push(v);

                depth[v] = depth[u]+1;

            }

        }

    }

    int ans=0;

    for (int i = 1; i <= n; i++)ans = max(ans,depth[i]);

    cout << ans;

}

by CAICAIA @ 2023-08-13 10:46:38

@WZRYWZWY

Because I don't know 因为我也RE

#include<bits/stdc++.h>
using namespace std;
int n,m;
struct node{
    int to;
    int last;
}edge[1001000];
int head[1100]={0},in[1100]={0},k=0;;
void add(int x,int y){
    k++;
    edge[k].to=y;
    edge[k].last=head[x];
    head[x]=k;
}
int aa[1100]={0};
int main(){
    int x;
    int sum=0,ans=0;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d",&x);
        for(int j=1;j<=x;j++){
            scanf("%d",&aa[j]);
        }
        int ki=2;
        for(int j=aa[1]+1;j<aa[x];j++){
            if(j==aa[ki]){
                ki++;
                continue;
            }
            for(int o=1;o<=x;o++){
                add(j,aa[o]);
                in[aa[o]]++;
                sum++;
            }
        }
    }
    /*
    for(int i=1;i<=n;i++){
        for(int j=head[i];j!=0;j=edge[j].last){
            printf("%d to %d\n",i,edge[j].to);

        }
        //printf("i=%d %d\n",i,in[i]);
    }
    */
    while(sum){
        //printf("sum=%d ans=%d\n",sum,ans);
        for(int i=1;i<=n;i++){
            //printf("in[%d]=%d\n",i,in[i]);
            if(in[i]==0){
                int op=edge[head[i]].last;
                //printf("sum=%d i=%d\n",sum,i);
                for(int j=head[i];j!=0;j=op){
                    //printf("dd%d to %d\n",i,edge[j].to);
                    in[edge[j].to]--;
                    sum--;
                    op=edge[j].last;
                    edge[j].last=0;
                }
                head[i]=0;
            } 
        }
        ans++;
    }
    cout<<ans+1;
    return 0;
}

by WZWZWZWY @ 2023-08-13 11:09:32

@Dai_Fu ……


by Magus @ 2023-08-13 14:47:15

@WZRYWZWY 需删除重边。


by WZWZWZWY @ 2023-08-13 14:50:40

@Bernie_qwq 嗯


by Magus @ 2023-08-13 14:51:18

@WZRYWZWY 所以能不能关注@Bernie_qwq 谢谢喵!


by WZWZWZWY @ 2023-08-13 14:51:44

@Bernie_qwq 为什么会有重边呢QAQ


by Magus @ 2023-08-13 14:53:41

@WZRYWZWY 数据不保证没有重边吧(?


by WZWZWZWY @ 2023-08-13 14:55:57

@Bernie_qwq 我试试


by WZWZWZWY @ 2023-08-13 14:58:22

@Bernie_qwq 果然A了,感谢QAQ(话说为什么有重边就会RE啊)


|