POJ 2367 Topology

本文介绍了一种基于图的拓扑排序算法实现方法。通过使用C++编程语言,详细展示了如何利用队列来实现图的拓扑排序,并提供了完整的源代码示例。该算法适用于有向无环图,能够有效地解决任务依赖关系问题。
#include <iostream>
#include <vector>
#include <queue>
const int MAXN = 105;


int ind[MAXN];

std::vector<int> children[MAXN];

void topo(int n)
{
	std::queue<int> q;
	for(int i = 1; i <= n; i++)
	{
		if(ind[i] == 0)
			q.push(i);
	}

	while(!q.empty())
	{
		int cur = q.front();
		printf("%d ", cur);
		q.pop();
		int childrenCnt = children[cur].size();
		for(int i = 0; i < childrenCnt; i++)
		{
			ind[children[cur][i]]--;
			if(ind[children[cur][i]] == 0)
				q.push(children[cur][i]);
		}

	}
}

int main()
{
	int n;
	int tmp;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		while(1)
		{
			scanf("%d", &tmp);
			if(tmp == 0)
				break;
			children[i].push_back(tmp);
			ind[tmp]++;
		}
	}
	topo(n);
	printf("\n");
	return 0;
}

Chronology. In the year 2000 I was given two courses to teach: analysis and topology. The Analysis course was assigned to me due to an emergency redistribution; Topology was thrown in as an award for accepting to teach Analysis on such short notice. Algebraic topology, which covered only homotopy theory in its curriculum, was (re)introduced into the undergraduate-graduate program of the Mathematics Department (University of Manitoba) in 2004. I have taught these two courses almost continuously ever since. This book is primarily an upshot of my teaching lifestyle over these years. The level of the book, and the target audience. The book has two clearly differentiated parts: Part 1 is topology and Part 2 is homotopy. As indicated by the title of the book, we do not have any pretense to go very deeply into these subjects. On the other hand, neither could the content be described as too breezy, for we include most of the important theorems of the basic theory. The material covered in this book is on the fuzzy boundary between the undergraduate and the graduate level. One may tentatively state that Part 1 is mostly at the advanced undergraduate level, Part 2 is mostly at the early graduate level. Indeed, the Algebraic topology (Homotopy theory) course that I have been teaching has always been cross-listed, and has almost always been taken by both graduate and advanced undergraduate students. It is my hope that this book will bring this beautiful theory closer to the undergraduate curriculum.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值