虚位以待(AD)
虚位以待(AD)
首页 > 软件编程 > C/C++编程 > hdu 1285 确定比赛名次(给一个拓扑有序图要求输出拓扑有序序列)

hdu 1285 确定比赛名次(给一个拓扑有序图要求输出拓扑有序序列)
类别:C/C++编程   作者:码皇   来源:小红     点击:

1 如果有向图无回路,那么该图拓扑有序。2代码: include includeusing namespace std;int mat[505][505];int n,m;int in[505];void topological_sort(){ int cnt=n; while

1.如果有向图无回路,那么该图拓扑有序。

2代码:

 

    #include#includeusing namespace std;
    int mat[505][505];
    int n,m;
    int in[505];
    void topological_sort(){
    int cnt=n;
    while(cnt--) {
    int i;
    for(i=1;
    i<=n;
    i++) {
    if(in[i]==0) break;
    }
    printf(%d,i);
    in[i]=-1;
    if(cnt) {
    printf( );
    }
    for(int j=1;
    j<=n;
    j++) {
    in[j]-=(mat[i][j]);
    }
    }
    printf();
    }
    int main(){
    while(scanf(%d%d,&n,&m)==2) {
    memset(mat,0,sizeof(mat));
    memset(in,0,sizeof(in));
    for(int i=0;
    i int="" pre="" return="">

     

     

    >
相关热词搜索: 拓扑 名次 序列