Go: package main

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

const NIL = -1

type Node struct {
	id     int
	weight int
}

func init() {
	sc.Split(bufio.ScanWords)
}

type NodeHeap []Node

func (h NodeHeap) Len() int           { return len(h) }
func (h NodeHeap) Less(i, j int) bool { return h[i].weight < h[j].weight }
func (h NodeHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *NodeHeap) Push(x interface{}) {
	*h = append(*h, x.(Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()

	list := make([][]int, n)
	weight := make([]int, n)
	for i := range list {
		list[i] = make([]int, n)
		weight[i] = NIL
		for j := range list[i] {
			list[i][j] = NIL
		}
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		for j := 0; j < k; j++ {
			v := scanInt()
			w := scanInt()
			list[u][v] = w
		}
	}

	start := Node{id: 0, weight: 0}
	h := &NodeHeap{start}
	heap.Init(h)

	for h.Len() > 0 {
		node := heap.Pop(h).(Node)
		if weight[node.id] != NIL {
			continue
		}
		weight[node.id] = node.weight

		for i, w := range list[node.id] {
			if w == NIL {
				continue
			}
			heap.Push(h, Node{id: i, weight: w + node.weight})
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		fmt.Fprint(w, i)
		fmt.Fprint(w, " ")
		fmt.Fprint(w, weight[i])
		fmt.Fprintln(w)
	}
	w.Flush()
}

C++: #include <iostream>

using namespace std;

int n;
int a[124][124] = {{}};
static const int INFTY = 1000000;

void dijkstra(){
  int flag[124] = {};
  int d[124] = {};
  int p[124] = {};
  int minv;
  int u;

  for (int i = 0;i < n;i++){
    d[i] = INFTY;
    p[i] = -1;
  }
  d[0] = 0;
  while(1){
    minv = INFTY;
    u = -1;

    for(int i = 0;i < n;i++){
      if(flag[i] == 0 && minv > d[i]){
        minv = d[i];
        u = i;
      }
    }
  //  cout << "u = " << u << endl;
  //  cout << "minv = " << minv << endl;
    if(u == -1) break;
    flag[u] = 1;

    for(int i = 0;i < n;i++){
      if(d[i] > d[u] + a[u][i] && a[u][i] != INFTY && flag[i] == 0){
        d[i] = d[u] + a[u][i];
        p[i] = u;
      }
    }
  }

  for(int i = 0;i < n;i++){
    if(d[i] != -1){
      cout << i <<  " " << d[i] << endl;
    }
    else cout << i << " " << -1 << endl;
  }
}



int main(){

  cin >> n;

  for (int i = 0 ;i < n;i++){
    for(int j = 0;j < n;j++){
      a[i][j] = INFTY;
    }
  }


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

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define INF 200001 
using namespace std;
int n;
int A[1000][1000];
int D[1000][1000];
 
void Init(int f){
  for(int i=0;i<f;i++){
    for(int j=0;j<f;j++)D[i][j] = INF;
  } 
}
 
int main(){
  scanf("%d",&n);
  int u,k,C,V;
  Init(n);
  
  for(int i=0;i<n;i++){
      scanf("%d %d",&u,&k);    
      for(int j=0;j<k;j++){
    scanf("%d %d",&V,&C);
    D[u][V] = C;
   
      }    
  }
  for(int i=0;i<n;i++)D[i][i] = 0;

  for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j]= min(D[i][j],D[i][k] + D[k][j]);

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

C++: #include <iostream>
#include <queue>
#include <utility>
#include <vector>
#include <functional>
using namespace std;
int cost[100][100];
const int INF = 10000000;
int dijkstra(int n,int s,int g){
	typedef pair<int,int> P;
	int mincost;
	{priority_queue<P,vector<P>,greater<P> > pq;
	P p,tp;
	for(int i = 0;i < n;++i){
		p.first = cost[s][i];
		p.second = i;
		if(i == s) p.first = 0;
		pq.push(p);
	}
	while(!pq.empty()){
		p = pq.top();
		pq.pop();
		if(p.second == g) break;
		for(int i = 0;i < n;++i){
			if(cost[p.second][i] != INF && p.first != INF){
				tp.first = p.first + cost[p.second][i];
				tp.second = i;
				pq.push(tp);
			}
		}
	}
	mincost = p.first;
	}
	return mincost;
}
int main(){
	int n,m,a,b,c;
	cin >> n;
	for(int i = 0;i < 100;++i){
		for(int j = 0;j < 100;++j){
			cost[i][j] = INF;
		}
	}
	for(int i = 0;i < n;++i){
		cin >> a >> m;
		for(int j = 0;j < m;++j){
			cin >> b >> c;
			cost[a][b] = c;
		}
	}
	for(int i = 0;i < n;++i){
		cout << i << " " << dijkstra(n,0,i) << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>

struct Edge {
	int to, weight;
};

int main()
{
	int n, u, k, v, c, distance[100]{}, upd_num = 1;
	bool must_update[100]{ 1 };
	std::vector<Edge> dest[100];

	std::cin >> n;
	for (int i = 0; i < n; ++i)
	{
		std::cin >> u >> k;
		for (int j = 0; j < k; ++j)
		{
			std::cin >> v >> c;
			dest[u].push_back({ v, c });
		}
		if (i)
			distance[i] = 2000000000;
	}

	while (upd_num)
		for (int i = 0; i < n && upd_num; i++)
		{
			if (!must_update[i]) continue;

			must_update[i] = false;
			upd_num--;
			for (auto e : dest[i])
			{
				int tmp = distance[i] + e.weight;
				if (tmp < distance[e.to])
				{
					distance[e.to] = tmp;
					if (!must_update[e.to])
					{
						must_update[e.to] = true;
						upd_num++;
					}
				}
			}
		}

	for (int i = 0; i < n; i++)
	{
		std::cout << i << " " << distance[i] << std::endl;
	}

	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define MAX_V 100
#define INF 1e9
using namespace std;
int cost[MAX_V][MAX_V];
int d[MAX_V];
bool used[MAX_V];
int V;
void dijkstra(int s) {
	for (int i = 0; i < V; i++) {
		d[i] = INF;
		used[i] = false;
	}
	d[s] = 0;
	while (true) {
		int v = -1;
		for (int u = 0; u < V; u++) {
			if (!used[u] && ((v == -1) || d[u] < d[v])) {
				v = u;
			}
		}
		//全ての頂点が到達済み
		if (v == -1) {
			break;
		}
		//集合に新たに頂点を追加
		used[v] = true;
		for (int u = 0; u < V; u++) {
			d[u] = min(d[u], d[v] + cost[v][u]);
		}
	}
}

int main() {
	for (int i = 0; i < V; i++) {
		for (int j = 0; j < V; j++) {
			cost[i][j] = INF;
		}
	}
	cin >> V;
	for (int i = 0; i < V; i++) {
		int u;
		cin >> u;
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int v;
			cin >> v;
			int c;
			cin >> c;
			cost[u][v] = c;
		}
	}
	dijkstra(0);

	for (int i = 0; i < V; i++) {
		cout << i << " " << d[i] << endl;
	}
	return 0;
}

C++: #include <cstdio>
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, **M;
int *d;

void dijkstra() {
    int u, minv;
    int d[n], color[n];

    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[n] = WHITE;
    }
    d[0] = 0;

    while (1) {
        u = -1;
        minv = INFTY;
        for (int i = 0; i < n; i++) {
            if (color[i] != BLACK && d[i] < minv) {
                u = i;
                minv = d[i];
            }
        }

        if (u == -1) { break; }

        color[u] = BLACK;
        for (int v = 0; v < n; v++) {
            if (color[v] != BLACK && M[u][v] != INFTY) {
                if (d[u] + M[u][v] < d[v]) {
                    d[v] = d[u] + M[u][v];
                    color[v] = GRAY;
                }             
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i, d[i]);
    }
}

int main() {
    scanf("%d", &n);

    M = new int*[n];
    for (int i = 0; i < n; i++) {
        M[i] = new int[n];
        for (int j = 0; j < n; j++) {
            M[i][j] = INFTY;
        }
    }

    for (int i = 0; i < n; i++) {
        int u, k;
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; j++) {
            int v, c;
            scanf("%d %d", &v, &c);
            M[u][v] = c;
        }
    }

    dijkstra();

    return 0;
}