• 拓扑排序 : hdu 1285 示例


    #include <iostream>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <cmath>
    #include <vector>
    #include <stack>
    #include <deque>
    #include <queue>
    #include <bitset>
    #include <list>
    #include <map>
    #include <set>
    #include <iterator>
    #include <algorithm>
    #include <functional>
    #include <utility>
    #include <sstream>
    #include <climits>
    #include <cassert>
    #define BUG puts("here!!!");
    
    using namespace std;
    
    const int N = 505;
    int edge[N][N];
    int degree[N];
    int vis[N];
    int n, m;
    int main() {
    	while(cin >> n >> m) {
    		memset(edge, 0, sizeof(edge));
    		memset(degree, 0, sizeof(degree));
    		int a, b;
    		while(m--) {
    			cin >> a >> b;
    			if(edge[a][b]) continue;
    			edge[a][b] = 1;
    			degree[b]++;
    		}
    		int k = 0;
    		memset(vis, 0, sizeof(vis));
    		int temp;
    		for(int i = 1; i <= n; i++) {
    			for(int j = 1; j <= n; j++) {
    				if(degree[j] == 0 && !vis[j]) {
    					cout << j;
    					k++;
    					vis[j] = 1;
    					temp = j;
    					break;
    				}
    			}
    			for(int j = 1; j <= n; j++) {
    				if(edge[temp][j] == 1) {
    					degree[j]--;
    				}
    			}
    			if(k != n) cout << ' ';
    			else {
    				cout << endl;
    				break;
    			}
    		}
    	}
    	return 0;
    }			
    

  • 相关阅读:
    RedisDump安装报错
    安装mysql解压版时遇到的错误
    Docker 私有仓库 Harbor搭建与使用
    最好的6个Go语言Web框架
    安裝 drone CLI和使用drone
    使用 Kubernetes Helm 安装 Drone
    从ELK到EFK演进
    搭建helm私服ChartMuseum
    Helm3的使用
    Helm3部署安装
  • 原文地址:https://www.cnblogs.com/robbychan/p/3787204.html
Copyright © 2020-2023  润新知