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 <iostream>

using namespace std;

static const int N = 100;
static const int INF = 1000000;

struct Vertex {
    bool in_S;
    int min_cost;
    int parent;
};

class SSSP {
private:
    int matrix[N][N];
    Vertex vertex[N];
    int n;

public:
    SSSP()
    {
        cin >> n;

        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                matrix[i][j] = INF;

        int u;
        int k;
        int v;
        int c;
        for (int i = 0; i < n; i++)
        {
            cin >> u;
            cin >> k;
            for (int j = 0; j < k; j++)
            {
                cin >> v >> c;
                matrix[u][v] = c;
            }
        }
    }

    void dijkstra(int start)
    {
        for (int i = 0; i < n; i++)
        {
            vertex[i].in_S = false;
            vertex[i].min_cost = INF;
        }
        vertex[start].min_cost = 0;
        vertex[start].parent = -1;

        while (true)
        {
            int u = -1;
            int mincost = INF;
            for (int i = 0; i < n; i++)
            {
                if (!vertex[i].in_S && vertex[i].min_cost < mincost)
                {
                    mincost = vertex[i].min_cost;
                    u = i;
                }
            }

            if (mincost == INF)
                break;

            vertex[u].in_S = true;

            for (int v = 0; v < n; v++)
            {
                if (!vertex[v].in_S && matrix[u][v] != INF)
                {
                    if (vertex[u].min_cost + matrix[u][v] < vertex[v].min_cost)
                    {
                        vertex[v].min_cost = vertex[u].min_cost + matrix[u][v];
                        vertex[v].parent = u;
                    }
                }
            }
        }
    }

    void print()
    {
        for(int i = 0; i < n; i++)
            cout << i << " " << vertex[i].min_cost << endl;
    }
};

int main()
{
    SSSP mst;
    mst.dijkstra(0);
    mst.print();
}

C++: // https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/all/ALDS1_12_B
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

#define INFint 2e9+1

ll gcd(ll a, ll b) { return __gcd(a,b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main(){
// start
  struct edge {int to,cost;};
  int N;
  cin>>N;
  vector<vector<edge>> G(N,vector<edge>());
  for(int i(0);i<N;i++){
    int k,u;
    cin>>k>>u;
    for(int j(0);j<u;j++){
      int v,c;
      cin>>v>>c;
      G[k].push_back({v,c});
    }
  }
  vector<int> d(N);
  fill(d.begin(),d.end(),INFint);
  // first: cont, second: node number 
  priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
  int start = 0;
  d[start] = 0;
  q.push({0,start});

  while(!q.empty()){
    pair<int,int> p = q.top();q.pop();                                                  
    int v = p.second;
    //if (d[v] < p.first) continue;
    for (int i(0);i<int(G[v].size());i++){
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        q.push({d[e.to],e.to});
      }
    }
  }
// end
  for(int i(0);i<N;i++){
    cout << i <<" " << d[i] << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define MAX_E 1000000
#define MAX_V 100000
#define INF 1e9
typedef long long ll;
using namespace std;
/*??????????????????????????? O(V*E)*/

//??????from????????????to???????????????cost??????
struct edge{int from, to, cost;};
edge es[MAX_E]; //???
ll d[MAX_V];   //???????????¢
int V,E;        //V???????????°???E????????°

//s???????????????????????????????????????????????¢????±???????.
void Bellman_Ford(int s){
  for(int i=0; i<V ;i++) d[i]=INF;
  d[s]=0;
  while(true){
    bool update=false;
    for(int i=0; i<E ;i++){
      edge e = es[i];
      if(d[e.from] != INF && d[e.to]> d[e.from] + e.cost){
	d[e.to] = d[e.from] + e.cost;
	update = true;
      }
    }
    if(!update) break;
  }
}

//true??????????????????????????¨??????
bool find_negative_loop(){
  memset(d,0,sizeof(d));

  for(int i=0; i<V ;i++){
    for(int j=0; j<E ;j++){
      edge e = es[j];
      if(d[e.to] > d[e.from] + e.cost){
	d[e.to] = d[e.from] + e.cost;
	
	//n??????????????´??°???????????????????????????????????¨?????????
	if(i == V-1) return true;
      }
    }
  }
  return false;
}

int main(){
  cin>>V;
  for(int i=0;i<V;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0,v,c;j<k;j++){
      cin>>v>>c;
      es[E++]=(edge){u,v,c};
    }
  }
  
  for(int i=0;i<V;i++){
    Bellman_Ford(i);
    cout <<i<<" "<<d[0]<<endl;
  }
}