zoukankan      html  css  js  c++  java
  • UVA 10305:Ordering Tasks(拓扑排序)

    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <math.h>
    #include <limits.h>
    #include <map>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <set>
    #include <string>
    #define ll long long
    #define ms(a) memset(a,0,sizeof(a))
    #define pi acos(-1.0)
    #define INF 0x3f3f3f3f
    const double E=exp(1);
    const int maxn=1e3+10;
    using namespace std;
    int a[maxn][maxn];
    int way[maxn];
    int n,m;
    void toposort()
    {
    	for(int i=1;i<=n;i++)
    	{
    		for(int j=1;j<=n;j++)
    		{
    			if(way[j]==0)
    			{
    				way[j]--;
    				cout<<j;
    				if(i!=n)
    					cout<<" ";
    				for(int k=1;k<=n;k++)
    				{
    					if(a[j][k])
    						way[k]--;
    				}
    				break;
    			}
    		}
    	}
    	cout<<endl;
    }
    int main(int argc, char const *argv[])
    {
    	while(cin>>n>>m&&(n||m))//这个不是&&停止!!!
    	{
    		ms(a);
    		ms(way);
    		int x,y;
    		for(int i=1;i<=m;i++)
    		{
    			cin>>x>>y;
    			a[x][y]=1;
    			way[y]++;
    		}
    		toposort();
    	}
    	return 0;
    }
    
  • 相关阅读:
    6 、 图论—NP 搜索
    5 、 数值计算
    4 、 数论
    3 、 结构
    2 、 组合
    1 、 几何
    Dikstra 堆优化板子
    SPFA板子
    C++优先队列例子
    一些类使用的模板
  • 原文地址:https://www.cnblogs.com/Friends-A/p/10324439.html
Copyright © 2011-2022 走看看