拓扑排序求关键路径

#include "stdafx.h"
#include
#include
#include
#include
#include

using namespace std;
const int maxn=100;
const int inf=0x7fffffff;
struct edge{
	int v,w;

};
vectorG[maxn];
int n,m,indegree[maxn];
stacktoporder;
int ve[maxn]={0};
int vl[maxn];
bool topologicalsort(){
	int num=0;
	queueq;
	for(int i=0;imax)max=ve[i];
	return max;

}


int criticalpath(){
	memset(ve,0,sizeof(ve));
	if(topologicalsort()==false)return -1;
	int last=findmax();
	fill(vl,vl+n,last);//最晚结束时间初始为汇点的值

	while(!toporder.size()){
		int u=toporder.top();
		toporder.pop();
		for(int i=0;ivl[v]-w)vl[u]=vl[v]-w;

		}
	}
	for(int u=0;u"<

你可能感兴趣的:(图论)