链接

[https://vjudge.net/contest/281085#problem/D]

题意

有n个任务,有M个对先后顺序

然你输出最后的完成任务的顺序,有多种可能输出一种即可

分析

裸的拓扑排序,需要队列和vector

代码

#include<iostream>
#include<string.h>
#include<vector>
#include<queue>
using namespace std;
int n,m,a,b;
int in[110];
int main(){
//freopen("in.txt","r",stdin);
while(cin>>n>>m&&(n+m)){
vector<int> v1[110];
memset(in,0,sizeof(in));
for(int i=1;i<=m;i++)
{
cin>>a>>b;
v1[a].push_back(b);
in[b]++;
}
queue<int> q;
vector<int> v2; for(int i=1;i<=n;i++)
if(in[i]==0) q.push(i);
//cout<<q.size()<<endl;
while(!q.empty()){
int p=q.front();
q.pop();
v2.push_back(p);
for(int i=0;i<v1[p].size();i++){
in[v1[p][i]]--;
if(in[v1[p][i]]==0)
q.push(v1[p][i]);
}
}
for(int i=0;i<v2.size();i++)
cout<<v2[i]<<' ';
cout<<endl;
}
return 0;
}

Ordering Tasks的更多相关文章

  1. Ordering Tasks(拓扑排序+dfs)

    Ordering Tasks John has n tasks to do. Unfortunately, the tasks are not independent and the executio ...

  2. [SOJ] Ordering Tasks

    1940. Ordering Tasks Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description John has n task ...

  3. UVA.10305 Ordering Tasks (拓扑排序)

    UVA.10305 Ordering Tasks 题意分析 详解请移步 算法学习 拓扑排序(TopSort) 拓扑排序的裸题 基本方法是,indegree表示入度表,vector存后继节点.在tops ...

  4. 拓扑排序(Topological Order)UVa10305 Ordering Tasks

    2016/5/19 17:39:07 拓扑排序,是对有向无环图(Directed Acylic Graph , DAG )进行的一种操作,这种操作是将DAG中的所有顶点排成一个线性序列,使得图中的任意 ...

  5. Ordering Tasks UVA - 10305 图的拓扑排序

    John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...

  6. M - Ordering Tasks(拓扑排序)

    M - Ordering Tasks Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Descri ...

  7. [拓扑排序]Ordering Tasks UVA - 10305

    拓扑排序模版题型: John has n tasks to do.Unfortunately, the tasks are not independent and the execution of o ...

  8. UVa 10305 - Ordering Tasks (拓扑排序裸题)

    John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...

  9. Ordering Tasks 拓扑排序

    John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...

  10. UVA10305:Ordering Tasks(拓扑排序)

    John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...

随机推荐

  1. 区块链会与io域名有什么关系

    为什么区块链会与io域名有这么大的联系? 近几年,区块链成为各国央行到国内外各大商业银行.联合国.国际货币基金组织到许多国家政府研究机构讨论的热点,"区块链+"应用创新正在成为引领 ...

  2. Android Studio移除模块

    一.打开文件菜单下的项目结构 二.在项目结构中选中模块,点击-号,然后删除 三.删除本地文件,移除模块成功

  3. Linux进程启动过程分析do_execve(可执行程序的加载和运行)---Linux进程的管理与调度(十一)

    execve系统调用 execve系统调用 我们前面提到了, fork, vfork等复制出来的进程是父进程的一个副本, 那么如何我们想加载新的程序, 可以通过execve来加载和启动新的程序. x8 ...

  4. eclipse使用CXF3.1.*创建webservice服务端客户端以及客户端手机APP(一)

    eclipse使用CXF3.1.*创建webservice服务端客户端以及客户端手机APP(一) 本篇博客主要包含五个内容: 1.CXF换将搭建以及eclipse配置CXF. 2.eclipse创建w ...

  5. ACE侧边栏刷新自动展开之前的选择

    在body下面加上 <script type="text/javascript"> $(document).ready(function(){ var url = do ...

  6. Java程序设计教程(第2版)阅读总结

    为了重新拣起对Java的回忆,只好又找了本基础书.由于成都高新图书馆的计算机书实在不多,只能找到这本了.简单读了下Java部分,总结如下: 优点:虽然本书也是作者编的而不是作者著的,但是可以看出作者编 ...

  7. IO的详细解释:It's all about buffers: zero-copy, mmap and Java NIO

    There are use cases where data need to be read from source to a sink without modification. In code t ...

  8. [Python] 练习代码

    # from random import randrange # num = int(input('摇几次骰子: ')) # sides=int(input('筛子有几个面: ')) # sum=0 ...

  9. 配置DispatcherServlet应该写/还是/*

    相亲怎么做 web应用需要放在Tomcat容器中才能启动,Tomcat容器内有一个默认的web.xml文件,在自己项目中配置的XML文件都是继承自Tomcat中的全局XML文件并重写其中相应配置,这种 ...

  10. 002_浅析python 中__name__ = '__main__' 的作用

    很多新手刚开始学习python的时候经常会看到python 中__name__ = \'__main__\' 这样的代码,可能很多新手一开始学习的时候都比较疑惑,python 中__name__ = ...