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
随机推荐
- iOS-UITextField 全面解析
iOS中UITextField 使用全面解析 建议收藏,用到的时候来这里一查就都明白了 //初始化textfield并设置位置及大小 UITextField *text = [[UITextField ...
- 固比固布局 圣杯布局 css实现传统手机app布局
手机app的布局大致上都是头部.内容.底部三部分: 我们需要实现的是头部.底部高度固定:中间内容区域自适应且可以滚动:直接贴代码: css: html,body { width: 100%; heig ...
- 91.Bower : ENOGIT git is not installed or not in the PATH 解决方法
转自:https://www.haorooms.com/post/bower_error 今天在用bower安装依赖的时候,出现了Bower : ENOGIT git is not installed ...
- 15-11-23:system指令
CMD命令:开始->运行->键入cmd或command(在命令行里可以看到系统版本.文件系统版本) 1. appwiz.cpl:程序和功能 2. calc:启动计算器 3. certmgr ...
- HD-ACM算法专攻系列(9)——大菲波数
题目描述: 源码: 运用Java大数求解. import java.math.BigInteger; import java.util.*; public class Main { //主函数 pub ...
- sqlserver如何给某一用户分配只能查看某一视图的权限
exec sp_addrole 'guestview' --GRANT SELECT ON veiw TO [guestview]; GRANT SELECT ON CustomerInfo TO ...
- SSH框架下的多表增删改查
下载地址:SSH框架下的多表增删改查 点击进入码云Git下载 点击进入CSDN下载 项目结构: 项目代码就不全部贴出来了,只贴下核心代码.需要项目的自己可以去下载. package com.atgui ...
- python编程基础
Date: 2019-05-27 Author: Sun 1. 程序 为了完成某种特定功能,以某种程序设计语言编写的有序指令的集合.程序是指挥cpu工作的"工作手册".计算机只能执 ...
- Python内置数据结构之列表list
1. Python的数据类型简介 数据结构是以某种方式(如通过编号)组合起来的数据元素(如数.字符乃至其他数据结构)集合.在Python中,最基本的数据结构为序列(sequence). Python内 ...
- cuDNN编写卷积实例
转载至http://www.goldsborough.me/cuda/ml/cudnn/c++/2017/10/01/14-37-23-convolutions_with_cudnn/ Convolu ...