3. Given the following Go code snippet implementing Prim's Algorithm on a graph with edges:
edges := [][]int{{0,1,2},{1,2,3},{0,2,1}}
// Graph with 3 vertices and edges with weights
// What is the total weight of the minimum spanning tree printed by this code?
func primMST() int {
n := 3
graph := make([][]Edge, n)
for _, e := range edges {
graph[e[0]] = append(graph[e[0]], Edge{to: e[1], weight: e[2]})
graph[e[1]] = append(graph[e[1]], Edge{to: e[0], weight: e[2]})
}
visited := make([]bool, n)
pq := &PriorityQueue{}
heap.Init(pq)
heap.Push(pq, &Item{vertex: 0, weight: 0})
total := 0
for pq.Len() > 0 {
item := heap.Pop(pq).(*Item)
if visited[item.vertex] {
continue
}
visited[item.vertex] = true
total += item.weight
for _, e := range graph[item.vertex] {
if !visited[e.to] {
heap.Push(pq, &Item{vertex: e.to, weight: e.weight})
}
}
}
return total
}