简体   繁体   English

计算图中的MST数量

[英]Count number of MSTs in a graph

I thought about this problem many hours, but I didn't find any solutions 我好几个小时都在想这个问题,但没有找到解决办法

The problem is : 问题是 :

How many MSTs does the given graph have (MST := Minimum Spanning Tree) 给定图具有多少个MST(MST:=最小生成树)

the graph G is an undirected, connected graph 图G是无向的连通图

it's Guaranteed that no vertex's degree exceeds 3 :) 保证顶点的度数不超过3 :)

prefer C/C++ solutions (can understand like-code-formed Algorithm too) 更喜欢C / C ++解决方案(也可以理解类似代码的算法)

and please with a low order :) (running time) 并请以较低的顺序:)(运行时间)

UPDATE UPDATE

first of all finding all MSTs :) O( |E| log |E| ) 首先找到所有MST :) O(| E | log | E |)

others where worse :( 其他更糟糕的地方:(

You can try with a backtracking. 您可以尝试回溯。 In each step for one of 'leaf' vertices decide how many 'out' edges to use. 在“叶”顶点之一的每一步中,确定要使用多少“出”边。

function add_some_vertex_edges(leaves, edge):
  if |leaves| == |V|:
    num_of_MSTs += 1
    return
  v = leaves.pop()  # takes one vertex and removes it from leaves
  let v_edge be set of incident edges to v that are not already in edges and that don't make cycle if added to edges
  for each combination of edges from v_edge:
    add_edges(leaves + incident_vertices, edges + edge_combination)

add_some_vertex_edges({v}, {})

Since vertices degree is <= 3, for each leaf one edge is used to 'enter' it, and because of that |v_edge| 由于顶点度<= 3,因此对于每个叶子,一个边缘用于“输入”,因此| v_edge | <= 2, and because of that search tree is narrow. <= 2,并且由于该搜索树很窄。

Worst case running time is O(2^n), but probably in practical cases it is fast. 最坏的情况下运行时间是O(2 ^ n),但在实际情况下可能很快。 There are examples with worst case number of MSTs. 有一些MST的最坏情况的例子。 Example that I can think of is with two parallel lines of vertices and connections between them. 我能想到的示例是两条平行的顶点线和它们之间的连接。

O---O---O---O---O---O---O---O---O---
 \ /     \ /     \ /     \ /     \ /
  X       X       X       X       X ...
 / \     / \     / \     / \     / \
O---O---O---O---O---O---O---O---O---

In this example there are exactly 2^(n/2) MSTs. 在此示例中,恰好有2 ^(n / 2)个MST。 To calculate this, take 2 leftmost vertices. 要计算此角度,请选取2个最左边的顶点。 They can be connected to the rest of a graph in 4 ways. 它们可以通过4种方式连接到图形的其余部分。

O---O   O   O   O   O   O---O
         \ /     \ /     \ /
          X       X       X
         / \     / \     / \
O---O , O   O , O---O , O   O

For each group of interconnected 4 vertices there are 4=2^2 possibilities to choose from. 对于每组相互连接的4个顶点,有4 = 2 ^ 2种可能性可供选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM