我正在使用帶有Java中的PriorityQueue的Prim's Algorithm使用最小生成樹。但是,我得到的總重量(樹的最小重量)是錯誤的。 我誤解總重量背後的概念,或者是有一些問題,我的代碼? public int getMinSpanningTree(Graph g) {
int[][] matrix = g.getEdgeMatrix();
int totalVe
所以我得到這個僞代碼爲Prims算法, INPUT: GRAPH G = (V,E)
OUTPUT: Minimum spanning tree of G
Select arbitrary vertex s that exists within V
Construct an empty tree mst
Construct an empty priority queue Q that c
我已經制定了一個程序來實現prim的算法,但它並不像它應該那樣工作。 頂點在優先級隊列上得到改變,一個頂點甚至不改變它的權重和父級。 的代碼是 #include<stdio.h>
#include<stdlib.h>
typedef struct info
{
int parent;
int vertex;
int weight;
}info;
type