poj 2367
来源:互联网 发布:布兰诗歌 知乎 编辑:程序博客网 时间:2024/06/05 16:59
这是道简单的拓扑排序题目
题目大意
给出一个有向图,求出它的拓扑排序
解题思路
用degree表示其进入边数目,每次挑出一个入度为0的点输出,并将此点发出的边去掉
重复N次即可
代码如下
#include <stdio.h>using namespace std;#define Num 101int N,resultEnd = 1;int graph[Num][Num] = {};int degree[Num] = {};void findZeroLine(){ int i,j; for(i=1;i<=N;i++) if(degree[i] == 0) break; degree[i] = -1; printf("%d ",i); for(j=1;j<=N;j++) if(graph[i][j] == 1) degree[j]--;}int main(){ scanf("%d",&N); for(int i = 1;i <= N;i++) { int tmp; scanf("%d",&tmp); while(tmp != 0) { graph[i][tmp] = 1; degree[tmp]++; scanf("%d",&tmp); } } for(int i = 1;i <= N;i++) findZeroLine(); return 0;}
0 0
- POJ 2367
- poj 2367
- poj 2367
- (2367)POJ
- poj 2367
- poj 2367
- poj 2367 Genealogical tree
- poj 2367 Genealogical tree
- poj 2367 Genealogical tree
- POJ 2367 Topology
- POJ 2367 Genealogical tree
- poj 2367 拓扑排序
- poj 2367 Genealogical tree
- poj 2367 Genealogical tree
- POJ 2367 topological_sort
- POJ 2367 Genealogical tree
- poj 2367 拓扑排序
- poj 2367 拓扑排序
- 一款好用的JSON解析助手
- View Frame、bounds、clipsToBounds、masksToBounds
- 如何解决安卓SDK无法下载Package的问题
- Android隐藏ListView分割线
- VC驿站《VC++网络编程班》开课啦!
- poj 2367
- linux(centos)中tomcat开机启动 配置service和chkconfig
- 黑马程序员—网络编程
- 看见快乐快乐就了看见快乐
- 黑马程序员_Java基础——IO框架(上)(第5篇)
- 正则表达式截取URL参数
- 你不是正站在快乐
- ios视频学习3.2 类的声明和对象的创建—内存分析1
- JqueryMobile为Listview动态添加、删除查询功能