2#include <cgv/math/adjacency_list.h>
3#include <cgv/math/union_find.h>
4#include <cgv/math/fibo_heap.h>
13template <
typename v_type>
14void mst_prim(adjacency_list<v_type> &graph, adjacency_list<v_type> &mst)
16 if(graph.nverts() == 0)
19 std::vector<int> *vflags =
new std::vector<int>(graph.nverts(),0);
21 mst.resize(graph.nverts());
25 fibo_heap<double,adjacency_list<v_type>::edge_type*> heap;
28 for(
unsigned ei = 0; ei < graph.vertex(0).edges.size(); ei++)
30 adjacency_list<v_type>::edge_type *e = &(graph.vertex(0).edges[ei]);
31 heap.insert(e->weight,e);
36 adjacency_list<v_type>::edge_type *e = heap.delete_min();
38 if((*vflags)[e->end] == 0)
42 (*vflags)[e->end] = 1;
43 for(
unsigned ei = 0; ei < graph.vertex(e->end).edges.size(); ei++)
45 adjacency_list<v_type>::edge_type *e2 = &(graph.vertex(e->end).edges[ei]);
46 if( (*vflags)[e2->end] == 0)
47 heap.insert(e2->weight,e2);