回複:問JAVA 圖(graph)的算法(最大回路)(重新解釋)

給一個不怎麽efficient的算法。

Denote the start point as A, the weight limitation as V, the edge set as E
1.calculate a minimum spanning tree, T, rooted at the start point A
2. on the tree A, remove all nodes that have distances to A longer than V (actually it might be good to do this in the minimum spanning tree calculation), and also remove all edges connecting to the removed nodes, we get a tree T1, and edge set E1
3. Initialize a variable V_max = 0.
on T1, do a deep-priority traversal:
for each node been visited,
for each one of all edges in E1 of the current node except the edge on the tree T1, this edge forms a circle C, find the one with maximal value smaller than V, record this circle as C_temp; if C_temp has a weight bigger than V_max, record this circle as C_max and update V_max
4, Output C_max and V_max

請您先登陸,再發跟帖!