Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type Item struct {
	value    int // The value of the item; arbitrary.
	priority int // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }
func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}
func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}
func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}
func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

type Q struct {
	pq *PriorityQueue
	ds map[int]int // It has always same value as pq. For random access.
}

func newQ() *Q {
	pq := new(PriorityQueue)
	heap.Init(pq)
	return &Q{
		pq: pq,
		ds: make(map[int]int),
	}
}
func (q *Q) pop() (u, d int) {
	item := heap.Pop(q.pq).(*Item)
	delete(q.ds, item.value)
	return item.value, item.priority
}
func (q *Q) get(u int) (int, bool) { // returns d
	d, ok := q.ds[u]
	return d, ok
}
func (q *Q) set(u, d int) {
	q.ds[u] = d
	for _, item := range *q.pq {
		if item.value != u {
			continue
		}

		item.priority = d
		heap.Fix(q.pq, item.index)
		return
	}
	heap.Push(q.pq, &Item{
		priority: d,
		value:    u,
	})
}
func (q *Q) len() int {
	return len(q.ds)
}

func main() {
	r := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscan(r, &n)
	cs := make([]map[int]int, n) // []v_i -> c_i
	for h := 0; h < n; h++ {
		var u, k int
		fmt.Fscan(r, &u, &k)
		m := make(map[int]int)
		for i := 0; i < k; i++ {
			var v, c int
			fmt.Fscan(r, &v, &c)
			m[v] = c
		}

		cs[u] = m
	}

	q := newQ()
	q.set(0, 0)
	visited := make(map[int]struct{})
	out := make([]int, n)

	for q.len() > 0 {
		u, d := q.pop()
		for uu, c := range cs[u] {
			// Consider the connection between u and uu.
			if _, ok := visited[uu]; ok {
				continue
			}
			dd := d + c
			if d, ok := q.get(uu); !ok || d > dd {
				q.set(uu, dd)
			}
		}

		out[u] = d
		visited[u] = struct{}{}
	}

	for u, d := range out {
		fmt.Println(u, d)
	}
}

C++: //#include "stdc++.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <queue>
//#include "my_gettime.hpp"
//#include "my_random.hpp"
//#include "my_util.hpp"
//using namespace std;

struct Edge{
	Edge(int f, int s, int w){first = f; second = s; weight = w;};
	int first;
	int second;
	int weight;
};

struct NodeP{
	NodeP(){};
	NodeP(int i, int p, int w){id = i; prev = p; weight = w;}
	int id;
	int prev;
	int weight;
	bool operator<(const NodeP & inRhs) const{ return weight < inRhs.weight; }
	bool operator>(const NodeP & inRhs) const{ return weight > inRhs.weight; }
};

#define INF (1<<30)
class Graph{
public:
	Graph(int numnodes);
	//~Graph();
	void addEdge(Edge a);
	void addEdge_nonDirect(Edge e);
	std::vector<NodeP> dijkstra(int start);
	int numNodes;
	//Edge *adj;
	std::vector < std::vector<Edge> > adj;
};
Graph::Graph(int n){
	numNodes = n;
	//adj = (Edge *)malloc(sizeof(Edge)*n*n);
	adj.resize(n);
}
void Graph::addEdge(Edge e){
	//adj[ e.first * numNodes + e.second ] = e;
	adj[e.first].push_back(e);
}
void Graph::addEdge_nonDirect(Edge e){
	adj[e.first].push_back(e);
	Edge e2 = e;
	e2.first = e.second;
	e2.second = e.first;
	adj[e2.first].push_back(e2);
}
std::vector<NodeP> Graph::dijkstra(int start){
	//using P = pair<int , int>;
	int *cost = (int *)malloc(sizeof(int)*numNodes);
	char *flag = (char *)malloc(sizeof(char)*numNodes);
	for(int i=0;i<numNodes;i++) flag[i] = 0;
	for(int i=0;i<numNodes;i++) cost[i] = INF;
	cost[start]=0;
	std::priority_queue < NodeP ,std::vector<NodeP>, std::greater<NodeP> > Q;
	Q.push(NodeP(start,-1, 0));
	std::vector <NodeP> nodeps(numNodes);

	while( !Q.empty() ){
		NodeP node = Q.top();
		Q.pop();
		if( flag[node.id] == 1 ) continue;
		flag[node.id] = 1;
		cost[node.id] = node.weight;

		nodeps[node.id] = node;

		typedef std::vector<Edge>::iterator ITR;
		for( ITR itr = adj[node.id].begin(); itr !=adj[node.id].end(); itr++ ){
			int dis = node.weight + itr->weight;
			if( cost[itr->second] > dis ){
				Q.push(NodeP(itr->second, node.id, dis));
			}
		}

	}

	free(cost);
	free(flag);

	return nodeps;
}

int main(int argc ,char **argv){
	using namespace std;

	int numNodes;
	cin >> numNodes;

	Graph g(numNodes);

	for(int i=0;i<numNodes;i++){
		int nodeid, numedge;
		cin >> nodeid >> numedge;
		for(int j=0;j<numedge;j++){
			int target, weight;
			cin >> target >> weight;
		//	cout<< nodeid<<" "<<target<<" "<<weight<<endl;
			g.addEdge(Edge(nodeid,target,weight));
		}
	}
	vector<NodeP> nodeps = g.dijkstra(0);
	typedef std::vector<NodeP>::iterator ITR;
	for( ITR itr = nodeps.begin(); itr !=nodeps.end(); itr++ ){
		printf("%d %d\n",/*itr->prev,*/itr->id,itr->weight);
	}
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;

#define NUM 100
#define NIL -1
#define INF 1000000000
#define WHITE 0
#define BLACK 1
int node_num;
vector<tuple<int, int>> G[NUM];
int V[NUM];
int color[NUM];

void init(void){
    scanf("%d", &node_num);

    for(int i = 0; i < node_num; i++){
        int u, k;
        scanf("%d", &u);
        scanf("%d", &k);

        for(int j = 0; j < k; j++){
            int v_, c;
            scanf("%d", &v_);
            scanf("%d", &c);
            G[u].push_back(make_tuple(v_, c));
        }
    }

    for(int i = 0; i < node_num; i++){
        color[i] = WHITE;
        V[i] = INF;
    }
}

void updateAround(int n){
    color[n] = BLACK;
    for(int i = 0; i < G[n].size(); i++){
        V[get<0>(G[n][i])] = min(V[get<0>(G[n][i])], V[n] + get<1>(G[n][i]));
    }

    int min_index = NIL;
    int min_value = INF;
    for(int i = 0; i < node_num; i++){
        if(color[i] == BLACK){
            continue;
        }
        if(V[i] < min_value){
            min_value = V[i];
            min_index = i;
        }
    }
    if(min_index != NIL){
        updateAround(min_index);
    }
}

int main(void){
    init();

    V[0] = 0;
    updateAround(0);

    for(int i = 0; i < node_num; i++){
        printf("%d %d\n", i, V[i]);
    }
}

C++: #include <bits/stdc++.h>
const int INF = 100000;
using namespace std;

int main(void){
  bool used[100];
  int n, G[100][100], p[100];
  cin >> n;
  for(int i=0; i < 100; i++){
    used[i] = false;
    for(int j=0; j < 100; j++){
      G[i][j] = INF;
    }
  }
  for(int i=0; i < n; i++){
    int vtmp, k;cin >> vtmp >> k;
    for(int j=0; j < k; j++){
      int v, c; cin >> v >> c;
      G[vtmp][v] = c; G[v][vtmp] = c;
    }
  }

  int d[100];
  for(int i=0; i < n; i++){
    d[i] = INF;
  }
  d[0] = 0;

  for(int i=0; i < n; i++){
    int mind = INF;
    int minind;
    for(int j=0; j < n; j++){
      if(used[j] == false && d[j] < mind){
        mind = d[j]; minind = j;
      }
    }
    used[minind] = true;
    for(int j=0; j < n; j++){
      if(used[j] == false && G[minind][j] != INF){
        if(d[minind] + G[minind][j] < d[j]){
          d[j] = d[minind] + G[minind][j];
          p[j] = minind;
        }
      }
    }
  }
  for(int i=0; i < n; i++){
    cout << i << " " << d[i] << endl;
  }

  return 0;
}