Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

var infty = 1000000000

type DirectedGraphNodeID int

type DirectedGraphNode struct {
	key         DirectedGraphNodeID
	adjacents   []*DirectedGraphNode
	costs       []int
	distance    int
	predecessor *DirectedGraphNode
}

func newDirectedGraph(nNodes int) *DirectedGraph {
	graph := DirectedGraph{}
	graph.nodes = make([]*DirectedGraphNode, nNodes)
	for i := 0; i < nNodes; i++ {
		node := DirectedGraphNode{}
		node.key = DirectedGraphNodeID(i)
		node.distance = infty
		graph.nodes[i] = &node
	}
	return &graph
}

type DirectedGraph struct {
	nodes []*DirectedGraphNode
}

func (g *DirectedGraph) setAdjacency(i, j DirectedGraphNodeID, cost int) {
	g.nodes[i].adjacents = append(g.nodes[i].adjacents, g.nodes[j])
	g.nodes[i].costs = append(g.nodes[i].costs, cost)
}

func (g *DirectedGraph) print() {
	for i := 0; i < len(g.nodes); i++ {
		node := g.nodes[i]
		key := node.key
		strings := []string{strconv.Itoa(int(key)), strconv.Itoa(node.distance)}
		for j := 0; j < len(node.adjacents); j++ {
			nodeJ := fmt.Sprintf("(%v, %v)", node.adjacents[j].key, node.costs[j])
			strings = append(strings, nodeJ)
		}
		fmt.Printf("%v\n", strings)
	}
}

func (g *DirectedGraph) relaxEdge(l, r *DirectedGraphNode, w int) {
	if r.distance > l.distance+w {
		// fmt.Printf("%v -> %v, %v\n", l.key, r.key, l.distance+w)
		r.distance = l.distance + w
		r.predecessor = l
	}
}

func main() {
	scanner.Split(bufio.ScanWords)

	nNodes := nextInt()
	graph := newDirectedGraph(nNodes)

	for i := 0; i < nNodes; i++ {
		iNode := DirectedGraphNodeID(nextInt())
		nAdjacent := nextInt()
		for j := 0; j < nAdjacent; j++ {
			jNode := DirectedGraphNodeID(nextInt())
			cost := nextInt()
			graph.setAdjacency(iNode, jNode, cost)
		}
	}

	graph.nodes[0].distance = 0
	for iNode := 0; iNode < nNodes; iNode++ {
		for iLeft := 0; iLeft < len(graph.nodes); iLeft++ {
			nodeLeft := graph.nodes[iLeft]
			for iRight := 0; iRight < len(nodeLeft.adjacents); iRight++ {
				nodeRight := nodeLeft.adjacents[iRight]
				cost := nodeLeft.costs[iRight]
				graph.relaxEdge(nodeLeft, nodeRight, cost)
			}
		}
	}

	// graph.print()

	for iNode := 0; iNode < len(graph.nodes); iNode++ {
		node := graph.nodes[iNode]
		fmt.Println(node.key, node.distance)
	}
}

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

using namespace std;

#define NIL -1
#define INF 10000001

struct node{
  int key = INF;
};

node grf[100];
int hv[100][100], n;

void search(){
    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            if(hv[i][j] == NIL){
                continue;
            }
            if(grf[i].key + hv[i][j] < grf[j].key){
                grf[j].key = grf[i].key + hv[i][j];
            }
        }
    }
    return;
}

int main(){
    for(int i=0;i<100;++i){
        for(int j=0;j<100;++j){
            hv[i][j] = NIL;
        }
    }
    
    int p, token, vtal=0;
    cin >> n;
    
    for(int i=0;i<n;++i){
        cin >> p;
        cin >> p;
        vtal += p;
        for(int j=0;j<p;++j){
            cin >> token;
            cin >> hv[i][token];
        }
    }
    
    
    grf[0].key = 0;
    for(int i=0;i<vtal;++i){
        search();
    }
    
    
    for(int i=0;i<n;++i){
        cout << i << " " << grf[i].key << endl;
    }
    
    return 0;
}

C++: //Single Source Shortest Path I
#include <iostream>
#include <climits>
using namespace std;

static const int N = 100;
static const int WHITE = 0;
static const int BLACK = 1;
int n, A[N][N], colors[N], d[N];

void dijkstra() {
    int u, mind;
    for(int i = 0; i < N; i++) {
        colors[i] = WHITE;
        d[i] = INT_MAX;
    }
    d[0] = 0;
    while(1) {
        u = -1;
        mind = INT_MAX;
        for(int i = 0; i < n; i++) {
            if(colors[i] == WHITE && d[i] < mind) {
                u = i;
                mind = d[i];
            }
        }
        if(u == -1) break;
        colors[u] = BLACK;
        for(int i = 0; i < n; i++) {
            if(A[u][i] != -1) {
                d[i] = min(d[i], mind + A[u][i]);
            }
        }
    }

}

int main() {
    int u, k, v, c;
    cin >> n;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            A[i][j] = -1;
        }
    }
    for(int i = 0; i < n; i++) {
        cin >> u >> k;
        for(int j = 0; j < k; j++) {
            cin >> v >> c;
            A[u][v] = c;
        }
    }

    dijkstra();

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

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<vector<int> > vvi;
typedef vector<int> vi;
typedef vector<vector<bool> > vvb;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<string, int> psi;
typedef pair<int, int> pii;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define yn(f) (f?"yes":"no")
#define YN(f) (f?"YES":"NO")
#define Yn(f) (f?"Yes":"No")
#define mod 1000000007
#define intmax 2147483647
#define intmin -2147483648
#define longmax 9223372036854775807
#define longmin -9223372036854775808
int main() {
	int N;
	cin >> N;
	vvi A(N,vi(N,intmax));
	vi color(N,0);
	vi mincost(N,intmax);
	for (int i = 0; i < N; i++)
	{
		int u,k;
		cin >> u>>k;
		A[i].push_back(u);
		for (int j = 0; j < k; j++)
		{
			int v, w;
			cin >> v >> w;
			A[u][v] = w;
		}
	}
	color[0] = 127;
	mincost[0] = 0;
	while (true) {
		int minIndex = -1;
		for (int i = 0; i < N; i++)
		{
			if (color[i]==127&&(minIndex==-1||mincost[i]<mincost[minIndex]))minIndex = i;
		}
		if (minIndex==-1) break;
		color[minIndex] = 255;
		for (int i = 0; i < N; i++)
		{
			if (color[i]!=255&&A[minIndex][i]<intmax) {
				mincost[i] = min(mincost[i],mincost[minIndex]+ A[minIndex][i]);
				color[i] = 127;
			}
		}
	}
	for (int i = 0; i < N; i++)
	{
		cout << i << " " << mincost[i] << endl;
	}
};

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#define INF 1<<30
using namespace std;
int n;
int A[1000][1000];
int d[1000];
bool used[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;
  }

}

void djkstra(){
  for(int i=0;i<n;i++){
    d[i] = INF;
    used[i] = false;
  }
  d[0] = 0;

  while(true){
    int v = -1;
    for(int i=0;i<n;i++){
      if(!used[i] && (v == -1 || d[v] > d[i]))v = i;
    }
    if(v == -1)break;
    used[v] = true;
    for(int i=0;i<n;i++){
      d[i] = min(d[i],d[v] + D[v][i]);
    }
  }
}



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;
	D[V][u] = 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]);

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

  return 0;
}