zoukankan      html  css  js  c++  java
  • POJ2367【拓扑排序】

    很裸的拓扑排序~

    //#include <bits/stdc++.h>
    #include<iostream>
    #include<string.h>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    
    typedef __int64 LL;
    
    const int N=1e2+10;
    int ma[N][N];
    int pre[N];
    int n;
    
    void tuopu()
    {
        int k;
        int flag=0;
        for(int i=1;i<=n;i++)
        {
            k=0;
            for(int j=1;j<=n;j++)
            {
                if(!pre[j])
                {
                    pre[j]=-1;
                    if(flag) printf(" ");
                    printf("%d",j);
                    flag=1;
                    k=j;
                    break;
                }
            }
            if(!k)
                break;
            for(int j=1;j<=n;j++)
            {
                if(pre[j]!=-1&&ma[k][j])
                {
                    pre[j]--;
                }
            }
        }
    }
    
    int main()
    {
        scanf("%d",&n);
        memset(ma,0,sizeof(ma));
        memset(pre,0,sizeof(pre));
        for(int i=1;i<=n;i++)
        {
            while(1)
            {
                int x;
                scanf("%d",&x);
                if(!x)
                    break;
                ma[i][x]=1;
                pre[x]++;
            }
        }
        tuopu();
        return 0;
    }
  • 相关阅读:
    HDU 1002 A + B Problem II
    leetcode 42.接雨水
    无向图 及其术语
    C++优先队列详解
    C++优先队列详解
    最短路
    最短路
    CF DP练习题
    CF DP练习题
    干货
  • 原文地址:https://www.cnblogs.com/keyboarder-zsq/p/5934859.html
Copyright © 2011-2022 走看看