Tag: 算法有

给出有向图中循环的一个例子

我想要一个算法,如果有的话,在有向图中给出一个循环的实例。 谁能告诉我一个方向? 在伪代码中,或者最好是在Ruby中? 我之前问了一个类似的问题 ,并按照那里的建议,我在Ruby中实现了Kahn算法,它检测图形是否有一个循环,但我不仅要求它是否有一个循环,而且还要一个这样的循环的可能实例。 example_graph = [[1, 2], [2, 3], [3, 4], [3, 5], [3, 6], [6, 2]] 卡恩的算法 def cyclic? graph ## The set of edges that have not been examined graph = graph.dup n, m = graph.transpose ## The set of nodes that are the supremum in the graph sup = (n […]