Ordering Tasks
链接
[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的更多相关文章
- Ordering Tasks(拓扑排序+dfs)
Ordering Tasks John has n tasks to do. Unfortunately, the tasks are not independent and the executio ...
- [SOJ] Ordering Tasks
1940. Ordering Tasks Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description John has n task ...
- UVA.10305 Ordering Tasks (拓扑排序)
UVA.10305 Ordering Tasks 题意分析 详解请移步 算法学习 拓扑排序(TopSort) 拓扑排序的裸题 基本方法是,indegree表示入度表,vector存后继节点.在tops ...
- 拓扑排序(Topological Order)UVa10305 Ordering Tasks
2016/5/19 17:39:07 拓扑排序,是对有向无环图(Directed Acylic Graph , DAG )进行的一种操作,这种操作是将DAG中的所有顶点排成一个线性序列,使得图中的任意 ...
- Ordering Tasks UVA - 10305 图的拓扑排序
John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...
- M - Ordering Tasks(拓扑排序)
M - Ordering Tasks Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descri ...
- [拓扑排序]Ordering Tasks UVA - 10305
拓扑排序模版题型: John has n tasks to do.Unfortunately, the tasks are not independent and the execution of o ...
- UVa 10305 - Ordering Tasks (拓扑排序裸题)
John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...
- Ordering Tasks 拓扑排序
John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...
- UVA10305:Ordering Tasks(拓扑排序)
John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...
随机推荐
- Oracle EBS FA 本年折旧
FUNCTION get_ytd_deprn(p_asset_id IN NUMBER, p_book_type_code IN VARCHAR2, p_rate_source_rule IN VAR ...
- python创建列表和向列表添加元素方法
今天的学习内容是python中的列表的相关内容. 一.创建列表 1.创建一个普通列表 >>> tabulation1 = ['大圣','天蓬','卷帘'] >>> ...
- 【PAT】B1004 成绩排名
简单题 循环输入放入结构体数组,一个sort搞定 #include <stdio.h> #include<algorithm> using namespace std; str ...
- kafka_2.11-2.0.0_常用操作
参考博文:Kafka消费组(consumer group) 参考博文:kafka 1.0 中文文档(九):操作 参考博文:kafka集群管理工具kafka-manager部署安装 以下操作可以在min ...
- Kali 2.0 下 Metasploit 初始化配置
在kali 2.0中,命令行中直接输入msfconsole 提示不能连接到数据库 ,是由于postgresql 未启动.因此,需要开启postgresql,并且进行postgresql 的初始化配置. ...
- 【算法】LeetCode算法题-Valid Parentheses
这是悦乐书的第147次更新,第149篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第6题(顺位题号是20),给定一个只包含字符'(',')','{','}','['和'] ...
- ansys19.0安装破解教程(图文详解)
ansys19.0是一款非常著名的大型通用有限元分析(FEA)软件.该软件能够与多数计算机辅助设计软件接口,比如Creo, NASTRAN.Algor.I-DEAS.AutoCAD等,并能实现数据的共 ...
- Socket引子
=== ''' Socket网络编程: --应用层:http smtp dns ftp ssh snmp dhcp... 无论协议是什么本质上都是数据交换,总结为两种方式:收和发 --传输层(端口Po ...
- (转)Spring Boot 2 (十):Spring Boot 中的响应式编程和 WebFlux 入门
http://www.ityouknow.com/springboot/2019/02/12/spring-boot-webflux.html Spring 5.0 中发布了重量级组件 Webflux ...
- (转)Spring Boot(二十):使用 spring-boot-admin 对 Spring Boot 服务进行监控
http://www.ityouknow.com/springboot/2018/02/11/spring-boot-admin.html 上一篇文章<Spring Boot(十九):使用 Sp ...