hdoj

来源:互联网 发布:floyd 算法 改进 编辑:程序博客网 时间:2024/04/28 07:29
#include <stdio.h>int team[505][505];int degree[505];int N,M;int main(){     while(scanf("%d%d",&N,&M)!=EOF){   int i,j;   //初始化for(i=1;i<=N;i++){degree[i]=0;for(j=1;j<=N;j++)team[i][j]=0;        } //输入前驱        for(i=1;i<=M;i++){int p1,p2;scanf("%d%d",&p1,&p2);if(!team[p1][p2])degree[p2]++;//前驱的个数team[p1][p2]=1;        }    int count;for(count=1;count<=N;count++){for(i=1;i<=N;i++){if(degree[i]==0)//找一个没有前驱的点{degree[i]=-1;//标记//删除边for(j=1;j<=N;j++){if(team[i][j])//从i到其他的点的边degree[j]--;                    }printf("%d",i);if(count==N)putchar('\n');else putchar(' ');break;                }            }        }    }}

原创粉丝点击