Strongly Connected Components

堆栈C语言实现:https://www.cnblogs.com/tingshuo123/p/7090858.html

思路分析

使用tarjan算法,求解强连通分量。

  • 使用DFS后序遍历的过程中,对每一个节点V

    1. 放入堆栈Stack
    2. 标记到达的时序timeline和可以返回到的最低时序back
    3. 如果Vtimelineback相等,则说明此时堆栈顶到V的部分是一个强连通分量,输出强连通分量部分。

tarjan讲解

bilibili讲解:https://www.bilibili.com/video/BV19J411J7AZ?p=4&share_source=copy_web

调试

对于题目案例,我写出了相应的代码,附在结尾,可以根据这部分代码进行调试。

如果要测试其他案例数据,修改main()函数中G的值就可。

等效测试代码

#include <stdio.h>
#include <stdlib.h>#define MaxVertices 10  /* maximum number of vertices */
typedef int Vertex;     /* vertices are numbered from 0 to MaxVertices-1 */
typedef struct VNode *PtrToVNode;
struct VNode {Vertex Vert;PtrToVNode Next;
};
typedef struct GNode *Graph;
struct GNode {int NumOfVertices;int NumOfEdges;PtrToVNode *Array;
};Graph ReadG(); /* details omitted */void PrintV( Vertex V )
{printf("%d ", V);
}void StronglyConnectedComponents( Graph G, void (*visit)(Vertex V) );int main()
{// Graph G = ReadG();Graph G = (Graph)malloc(sizeof(struct GNode));G->NumOfEdges = 5;G->NumOfVertices = 4;G->Array = (PtrToVNode *)malloc(sizeof(struct VNode)*4);G->Array[0] = (PtrToVNode)malloc(sizeof(struct VNode));G->Array[0]->Vert = 1;G->Array[0]->Next = NULL;G->Array[1] = (PtrToVNode)malloc(sizeof(struct VNode));G->Array[1]->Vert = 2;G->Array[1]->Next = NULL;G->Array[2] = (PtrToVNode)malloc(sizeof(struct VNode));G->Array[2]->Vert = 0;G->Array[2]->Next = NULL;G->Array[3] = (PtrToVNode)malloc(sizeof(struct VNode));G->Array[3]->Vert = 2;G->Array[3]->Next = NULL;G->Array[3]->Next = (PtrToVNode)malloc(sizeof(struct VNode));G->Array[3]->Next->Vert = 1;G->Array[3]->Next->Next = NULL;StronglyConnectedComponents( G, PrintV );return 0;
}/* Your function will be put here */

FDS-HW11 6-1 Strongly Connected Components相关推荐

  1. JavaScript实现strongly Connected Components 强连通分量算法(附完整源码)

    JavaScript实现strongly Connected Components 强连通分量算法(附完整源码) Comparator.js完整源代码 LinkedListNode.js完整源代码 L ...

  2. Tarjan's strongly connected components algorithm的一些想法

    Tarjan的极大强连通子图(strongly connected components,SCC)算法基于深度优先遍历(DFS)实现.本文就尝试从深度优先遍历的角度思考一下Tarjan的方法是如何找出 ...

  3. 强连通分量(strongly connected components)

    强连通分量(strongly connected components)    徐不可说        2018/8/4                                        ...

  4. 图论学习六之Strongly connected components强连通分量

    强连通分量(Strongly connected cmponents) • 在有向图G中,如果任意两个不同的顶点相互可达,则称该有向   图是强连通的.有向图G的极大强连通子图称为<

  5. 强连通分量(SCC, Strongly Connected Components)

    强连通分量(SCC, Strongly Connected Component) 强连通分量的概念 强连通分量的应用 强连通分量的算法--Tarjan算法 强连通分量的概念 在有向图中,任意两个顶点 ...

  6. C#,图论与图算法,寻找图强连通单元(Strongly Connected Components)的罗伯特·塔扬(Robert Tarjan‘s Algorithm)算法与源程序

    Tarjan算法是一种高效的图算法,它利用图的深度优先搜索遍历,在线性时间内找到有向图中的强连通分量.使用的关键思想是,强连通组件的节点在图的DFS生成树中形成子树. 将有向图划分为强连通分量的任务非 ...

  7. 6-10 Strongly Connected Components(30 分)

    为了便于测试也写了ReadG() 自己测试没问题,但目前仍无法通过测试样例 怀疑是结构体指针的分配与题目用意不符, 另外孤立点的输入格式不明 Tarjan算法参考修改自: http://blog.cs ...

  8. [PTA] Strongly Connected Components

    算法参考了网上资料(Tarjan算法),嫌麻烦并没有使用给出的函数指针. #include <stdio.h> #include <stdlib.h>#define MaxVe ...

  9. HDU 4635 Strongly connected(缩点、最多可加边数使得仍然非强连通)

    整理的算法模板合集: ACM模板 HDU 4635 Strongly connected Give a simple directed graph with N nodes and M edges. ...

最新文章

  1. 如何正确地运用人工智能模型?
  2. 关于IsolatedStorageFile存取文件的问题
  3. 筒灯智能驱动芯片作用_魅族携8款智能照明新品进军智能家居,剑指行业前三...
  4. [css] 举例说明shape-outside的属性的用途有哪些?
  5. python 3 5_零基础学Python3(5):基础运算符(上)
  6. python json.dumps慢_python json.dumps中文乱码问题解决
  7. @程序员,入门爬虫看这一篇就够了!
  8. 学习springBoot(8)RabbitMQ
  9. 高等数学|微积分(上)知识点总结
  10. matlab读取jpg图片出错,求助,Matlab读取图片进行分类。出现错误
  11. 9月25日百度大脑开放日人像特效专场火热报名中!
  12. 出圈!迅镭激光切割设备亮相热播剧《麓山之歌》
  13. 瀑布流 ajax 预载入 json
  14. 禁用Chrome跟随系统的DPI缩放
  15. Vue2源码的学习日记(3)
  16. 51NOD L4-第三章 树 刷题记录-zgw
  17. 学计算机的一定要独立显卡嘛,电脑没有独立显卡会怎么样
  18. 好的代码是优质资产、莫让代码成为负债
  19. 背靠百度,度小满金融越来越稳
  20. android平板吃鸡开什么画质,ipad2018玩吃鸡可以开什么画质 | 手游网游页游攻略大全...

热门文章

  1. wav文件 服务器失败,.wav存储在服务器上的声音文件在加载web应用程序时无法播放...
  2. 桂林理工大学计算机网络技术专业学费,2020年桂林理工大学学费是多少
  3. MySql重装失败解决办法
  4. Java网络编程基础学习
  5. 被中国移动dns劫持了,怎么让它停止劫持?
  6. html中的audio
  7. OpenGL的glPushMatrix和glPopMatrix矩阵栈顶操作函数详解
  8. 电脑开机显示器无反应,主机正常-解决思路,解决办法
  9. 书论48 米芾《论书帖》
  10. Auified发布吉他效果器​AmpLion 2 Rock Essentials