UVa 10305 Ordering Tasks【拓扑排序】
题意:给出n件事情,m个二元组关系,求它们的拓扑序列
用的队列来做
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i) typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=;
int ecnt;
int n,m; int g[][],in[],ans[maxn]; void toposort(){
queue<int> q; for(int i=;i<=n;i++)
if(in[i]==) q.push(i); int cnt=;
while(!q.empty()){
int tmp=q.front();q.pop();
ans[++cnt]=tmp; for(int j=;j<=n;j++){
if(g[tmp][j]){
in[j]--;
if(in[j]==) q.push(j);
}
}
} printf("%d",ans[]);
for(int i=;i<=cnt;i++)
printf(" %d",ans[i]);
printf("\n");
} int main(){
while(scanf("%d %d",&n,&m)!=EOF){
if(n==&&m==) break; memset(g,,sizeof(g));
memset(in,,sizeof(in)); while(m--){
int u,v;
cin>>u>>v;
g[u][v]=;
in[v]++;
}
toposort();
}
return ;
}
UVa 10305 Ordering Tasks【拓扑排序】的更多相关文章
- UVA.10305 Ordering Tasks (拓扑排序)
UVA.10305 Ordering Tasks 题意分析 详解请移步 算法学习 拓扑排序(TopSort) 拓扑排序的裸题 基本方法是,indegree表示入度表,vector存后继节点.在tops ...
- UVa 10305 - Ordering Tasks (拓扑排序裸题)
John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...
- Uva 10305 - Ordering Tasks 拓扑排序基础水题 队列和dfs实现
今天刚学的拓扑排序,大概搞懂后发现这题是赤裸裸的水题. 于是按自己想法敲了一遍,用queue做的,也就是Kahn算法,复杂度o(V+E),调完交上去,WA了... 于是检查了一遍又交了一发,还是WA. ...
- UVA 10305 Ordering Tasks(拓扑排序的队列解法)
题目链接: https://vjudge.net/problem/UVA-10305#author=goodlife2017 题目描述 John有n个任务,但是有些任务需要在做完另外一些任务后才能做. ...
- Ordering Tasks UVA - 10305 图的拓扑排序
John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...
- UVA - 10305 Ordering Tasks(拓扑排序)
题意:给定优先关系进行拓扑排序. 分析:将入度为0的点加入优先队列,并将与之相连的点入度减1,若又有度数为0的点,继续加入优先队列,依次类推. #pragma comment(linker, &quo ...
- UVa 10305 Ordering Tasks (例题 6-15)
传送门: https://uva.onlinejudge.org/external/103/10305.pdf 拓扑排序(topological sort)简单题 自己代码的思路来自: ==> ...
- M - Ordering Tasks(拓扑排序)
M - Ordering Tasks Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descri ...
- Ordering Tasks 拓扑排序
John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...
- uva 10305 ordering tasks(超级烂题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABHIAAAHDCAYAAABI5T2bAAAgAElEQVR4nOydPY7svLW1awQGNABHCm
随机推荐
- HDU 5296 Annoying problem dfs序 lca set
Annoying problem Problem Description Coco has a tree, whose nodes are conveniently labeled by 1,2,…, ...
- nyoj--325--zb的生日(简单dp)
zb的生日 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 今天是阴历七月初五,acm队员zb的生日.zb正在和C小加.never在武汉集训.他想给这两位兄弟买点什么庆祝 ...
- Ubuntu下使用Deepin-wine的移植版安装qq微信等
title: Ubuntu下使用Deepin-wine的移植版安装qq微信等 toc: false date: 2018-09-18 16:12:49 categories: methods tags ...
- Bringing up the Avnet MicroZed with Vivado
Bringing up the Avnet MicroZed with Vivado I recently received the Adam Taylor Edition of Avnet's Zy ...
- 循环访问 TreeView 控件的所有节点
创建测试每个节点的递归过程 . private void PrintRecursive(TreeNode treeNode) { // Print the node. System.Diagnosti ...
- .Net垃圾回收和大对象处理
本文引自:http://www.cnblogs.com/yukaizhao/archive/2011/11/21/dot_net_gc_large_object_heap.html CLR垃圾回收器根 ...
- Python基本语法(基于3.x)
Python的两种运行模式: 命令行模式,运行python,然后在命令行中输入python命令 程序脚本, 在命令行中输入 ./hello.py运行 Python是解释形语言,但可以通过工具打包成二进 ...
- bioinformaitcs的latex版本参考文献填坑
最近实验室投bioinfomatics的刊,编辑说要把参考文献的格式改成不带方括号的,而且加点,而且只保留前三作者,之后用et al. 折腾了一下午,终于弄出来了. 首先,导言区需要添加: \make ...
- 你不知道的JavaScript(二)数组
作为一种线性数据结构,几乎每一种编程语言都支持数组类型.和c++.java这些强类型的语言相比,JavaScript数组有些不同,它可以存放任意类型的值.上节中有提到过JS中任意类型的值都可以赋值给任 ...
- solarwinds之网络发现
1. 首先需要添加网络发现 2. 使用public 3. 添加主机 4. 网络地址选择 5. 默认下一步 6. 运行发现 7. 扫描结构如下 8. 下一步 ...