Go: package main

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

const (
	MAX_N      = 10000
	MAX_WEIGHT = 100000
)

type Edge struct {
	start  int
	end    int
	weight int
}

type ShortestInfo struct {
	edges    []Edge
	shortest int
}

type Neighbor struct {
	node   int
	weight int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	shortestList := make([]ShortestInfo, n)
	for i := 1; i < n; i++ {
		shortestList[i] = ShortestInfo{edges: []Edge{}, shortest: MAX_N*MAX_WEIGHT + 1}
	}

	adjacentMatrix, err := createAdjacentMatrix(n, sc)
	if err != nil {
		panic(err)
	}

	sssp([]int{0}, shortestList, adjacentMatrix)
	for _, v := range shortestList {
		fmt.Printf("%d %d\n", v.getEnd(), v.shortest)
	}
}

func (si ShortestInfo) getEnd() int {
	if len(si.edges) == 0 {
		return 0
	} else {
		return si.edges[len(si.edges)-1].end
	}
}

func createAdjacentMatrix(n int, sc *bufio.Scanner) ([][]Neighbor, error) {
	adjacentMatrix := make([][]Neighbor, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		adjacentMatrix[id] = []Neighbor{}
		vertexNum, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		for j := 0; j < vertexNum; j++ {
			v, err := nextInt(sc)
			if err != nil {
				return nil, err
			}
			c, err := nextInt(sc)
			if err != nil {
				return nil, err
			}
			adjacentMatrix[id] = append(adjacentMatrix[id], Neighbor{v, c})
		}
	}
	return adjacentMatrix, nil
}

func sssp(nodeStack []int, shortestList []ShortestInfo, adjacentMatrix [][]Neighbor) {
	for len(nodeStack) > 0 {
		currentNode := nodeStack[0]
		nodeStack = nodeStack[1:]
		currentShortest := getShortest(currentNode, shortestList)
		adjacents := findAdjacents(currentNode, adjacentMatrix)
		for i := 0; i < len(adjacents); i++ {
			adj := adjacents[i]
			if currentShortest.shortest+adj.weight < getShortest(adj.end, shortestList).shortest {
				setShortest(adj.end, adj, currentShortest, shortestList)
				nodeStack = append(nodeStack, adj.end)
			}
		}
	}
}

func getShortest(node int, shortestList []ShortestInfo) ShortestInfo {
	return shortestList[node]
}

func setShortest(node int, edge Edge, currentShortest ShortestInfo, shortestList []ShortestInfo) {
	newEdges := make([]Edge, len(currentShortest.edges)+1)
	for i := 0; i < len(newEdges)-1; i++ {
		newEdges[i] = currentShortest.edges[i]
	}
	newEdges[len(newEdges)-1] = edge
	shortestInfo := ShortestInfo{edges: newEdges, shortest: currentShortest.shortest + edge.weight}
	shortestList[node] = shortestInfo
}

func findAdjacents(currentNode int, adjacentMatrix [][]Neighbor) []Edge {
	adjacents := adjacentMatrix[currentNode]
	edges := []Edge{}
	for _, neighbor := range adjacents {
		edges = append(edges, Edge{start: currentNode, end: neighbor.node, weight: neighbor.weight})
	}
	return edges
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

C++: //
//  main.cpp
//
//
//  Created by ???????????? on 2017/10/23.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <queue>
#include <algorithm>


#define n_max 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 1<<20

using namespace std;

int n, M[n_max][n_max], color[n_max], d[n_max], p[n_max];

void init(){
    int i, j, id, num, node;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            M[i][j] = INFTY;
        }
    }
    
    
    for(i = 0; i < n; i++){
        scanf("%d %d", &id, &num);
        for(j = 0; j < num; j++){
            scanf("%d", &node);
            scanf("%d", &M[id][node]);
        }
        color[i] = WHITE;
        d[i] = INFTY;
    }
}

void dijkstra(){
    //initializing
    d[0] = 0;
    p[0] = -1;
    
    priority_queue<pair<int, int>> PQ;
    
    PQ.push(make_pair(0, 0));
    
    int u;
    while(!PQ.empty()){
        //first weight, second idx
        pair<int, int> f= PQ.top(); PQ.pop();
        u = f.second;
        color[u] = BLACK;
        
        if(d[u] < f.first*(-1)) continue;
        
        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] = M[u][v] + d[u];
                    PQ.push(make_pair(d[v]*(-1), v));
                    color[v] = GRAY;
                }
            }
        }
    }
    for(int i = 0; i < n; i++){
        cout<<i<<" "<<d[i]<<endl;
    }
}

int main(int argc, const char * argv[]) {
    init();
    dijkstra();
    return 0;
}

C++: #include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int n, u, k, v, c;
	cin >> n;
	vector<vector<pair<int, int>>> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> u >> k;
		for (int j = 0; j < k; ++j) {
			cin >> v >> c;
			a[u].emplace_back(v, c);
		}
	}
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> b;
	b.emplace(0, 0);
	vector<bool> d(n);
	vector<int> e(n, INT_MAX);
	e[0] = 0;
	while (!b.empty()) {
		pair<int, int> f = b.top();
		b.pop();
		d[f.second] = true;
		for (int i = 0; i < a[f.second].size(); ++i) {
			if (!d[a[f.second][i].first]) {
				if (a[f.second][i].second + e[f.second] < e[a[f.second][i].first]) {
					e[a[f.second][i].first] = a[f.second][i].second + e[f.second];
					b.emplace(e[a[f.second][i].first], a[f.second][i].first);
				}
			}
		}
	}
	for (int i = 0; i < n; ++i) cout << i << ' ' << e[i] << endl;
}

C++: #include <iostream>
#include <cstdlib>
using namespace std;

#define INF 100000000

typedef struct state {
  int pos, cost;
} state;

state A[2000001];
int N = 0;

int parent (int i) { return i/2;}
int left ( int i) {return i * 2;}
int right ( int i ) {return i * 2 + 1;}

void swap( state* a, state* b ) {
  state tmp = *a;
  *a = *b;
  *b = tmp;
}

void minHeapify ( int i ) {
  int l = left(i);
  int r = right(i);
  int small;

  if ( l <= N && A[l].cost < A[i].cost ) small = l;
  else small = i;

  if ( r <= N && A[r].cost < A[small].cost ) small = r;

  if ( small != i ) {
    swap ( &A[i], &A[small] );
    minHeapify(small);
  }
}

state heapExtractMin() {
  if ( N < 1 ) return (state) {0,0};
  state min = A[1];
  A[1] = A[N];
  N--;
  minHeapify(1);
  return min;
}

void heapIncreaseKey( int i , state key ) {
  if ( key.cost > A[i].cost) return;

  A[i] = key;
  while ( i > 1 && A[parent(i)].cost > A[i].cost ) {
    swap( &A[i], &A[parent(i)]);
    i = parent(i);
  }
}

void minHeapInsert( state key ) {
  N++;
  A[N] = (state) { INF, INF };
  heapIncreaseKey(N, key);
}

typedef struct edge{
  int to,cost;
} edge;

edge* G[10000];
int size[10000];
int n;
int d[10000];
edge e;
state s;

int main() {
  int a,b;
  cin >> n;
  for ( int i = 0; i < n; i++ ) {
    cin >> a >> b;
    G[a] = (struct edge*)malloc( sizeof(edge )*b );
    size[a] = b;
    for ( int j = 0; j < b; j++ ) {
      cin >> G[a][j].to >> G[a][j].cost;
    }
    d[i] = INF;
  }
  d[0] = 0;
  minHeapInsert ( (state{0,0} ) );
  while(N!=0) {
    s = heapExtractMin();
    if ( s.cost > d[s.pos]) continue;
    for ( int i = 0; i < size[s.pos]; i++ ) {
      e = G[s.pos][i];
      if ( d[e.to] <= d[s.pos] + e.cost ) continue;
      d[e.to] = d[s.pos] + e.cost;
      minHeapInsert((state){e.to,d[e.to]});
    }
  }
  for ( int i = 0; i < n; i++ ) {
    cout << i << " " << d[i] << endl;
  }
}