Advertisement

C++课程涵盖图论基础及拓扑排序,并深入探讨AOV与AOE的关键路径对比

阅读量:

图的总结

图的总结

拓扑排序的核心在于识别关键节点,通过indegree数组来实现这一过程–

方法一:没有用队列

初始化时,将每个节点的入度信息存储于int inDegree[maxn] = { 0 };数组中。

按照以下步骤进行处理:

  • 寻找当前入度为零的节点
  • 移除该节点所关联的所有边,并相应地减少其他节点的入度值
  • 不断重复上述过程,直至无法找到新的入度为零的节点,此时返回-1作为标识。
复制代码
    /*initialize map and degree*/
    void init()
    /*get dot in 0 degree*/
    int getDegree()
    /*delete chosen dot outdegree */
    void updateIndegree(int s)
    
    bool topologicalSort()
    {
    	int s, ans = N;
    	while (true)
    	{
    		s

全部评论 (0)

还没有任何评论哟~