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
}

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) ([][]int, error) {
	adjacentMatrix := make([][]int, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		adjacentMatrix[id] = make([]int, n)
		for j := 0; j < n; j++ {
			adjacentMatrix[id][j] = -1
		}
		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][v] = c
		}
	}
	return adjacentMatrix, nil
}

func sssp(nodeStack []int, shortestList []ShortestInfo, adjacentMatrix [][]int) {
	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 [][]int) []Edge {
	adjacents := adjacentMatrix[currentNode]
	edges := []Edge{}
	for i, v := range adjacents {
		if v >= 0 {
			edges = append(edges, Edge{start: currentNode, end: i, weight: v})
		}
	}
	return edges
}

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

C++: 
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner in = new Scanner(System.in);

		int u = in.nextInt();
		int[][] mat = new int[u][u];
		for (int i = 0; i < u; i++) {
			Arrays.fill(mat[i], -1);
		}
		for (int i = 0; i < u; i++) {
			int fromNode = in.nextInt();
			int toNodeCount = in.nextInt();
			for (int j = 0; j < toNodeCount; j++) {
				int toNode = in.nextInt();
				int edgeWeight = in.nextInt();
				mat[fromNode][toNode] = edgeWeight;
			}
		}

		// solve
		Set<Integer> x = new HashSet<>();
		Set<Integer> y = new HashSet<>();
		boolean[] visit = new boolean[u];
		for (int i = 1; i < u; i++) {
			y.add(i);
		}
		int[] nodeCost = new int[u];
		Arrays.fill(nodeCost, Integer.MAX_VALUE);
		x.add(0);
		nodeCost[0] = 0;
		visit[0] = true;

		while (!y.isEmpty()) {
			int min = Integer.MAX_VALUE;
			int v = -1;
			for (int from : x) {
				for (int to = 0; to < u; to++) {
					int visitCost = mat[from][to] + nodeCost[from];
					// toのノードが最小コストで訪問済でない場合
					if (mat[from][to] != -1 && !visit[to] && visitCost <= nodeCost[to]) {
						nodeCost[to] = visitCost;
						if (nodeCost[to] < min) {
							min = nodeCost[to];
							v = to;
						}
					}
				}
			}
			x.add(v);
			y.remove(v);
			visit[v] = true;
		}

		for (int i = 0; i < u; i++) {
			System.out.println(i + " " + nodeCost[i]);
		}
	}

}

C++: // ※注意t C++14でコンパイルしないとエラーがでます
// ダイクストラ法
// ALDS1_12_C http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_12_C&lang=jp
#include <bits/stdc++.h>
using namespace std;

struct Vertex {                       // 頂点の情報を構造体Vertexで表す
    vector<pair<int, int>> neighbor;  // 隣接する頂点とそこまでの距離
    bool fixed = false;               // この頂点が確定しているか否か
    int fixed_cost = 0;               // 確定したコスト（始点からの最短距離）
};

int main(void) {
    // ■■ 初期化・データの読み込み ■■ 　
    int n;
    cin >> n;
    Vertex vertexs[n];  // n個の頂点を用意する
    for(int i = 0; i < n; i++) {
        int v, k;  // v:頂点　　k:vに隣接する頂点の数
        cin >> v >> k;
        for(int j = 0; j < k; j++) {
            int vi, ci;
            cin >> vi >> ci;
            vertexs[v].neighbor.push_back(make_pair(ci, vi));  // 各頂点vに対して、（隣接する頂点までのコスト(距離) と　その隣接頂点 ）をneighbor に読み込む
        }
    }

    // ■■ ダイクストラ法を実行 ■■ 　
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;  // pair< 出発点からの頂点までのコスト , 頂点 > の値を持つpriority_queue　（greaterにしないと昇順にならない）
    que.push(make_pair(0, 0));
    while(!que.empty()) {
        int cost = que.top().first;
        int v = que.top().second;
        que.pop();
        if(vertexs[v].fixed == false) {
            vertexs[v].fixed = true;
            vertexs[v].fixed_cost = cost;
            for(int i = 0; i < int(vertexs[v].neighbor.size()); i++) {
                int vi = vertexs[v].neighbor[i].second;  // vi: 頂点vに隣接するi番目の頂点
                int ci = vertexs[v].neighbor[i].first;   // ci: 頂点vから頂点viまでのコスト
                if(vertexs[vi].fixed == false) {
                    que.push(make_pair(cost + ci, vi));
                }
            }
        }
    }

    for(int i = 0; i < n; i++) {
        cout << i << " " << vertexs[i].fixed_cost << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define INF 1000000000
#define MAX_N 10000
using namespace std;
int n;
int d[MAX_N];

struct edge {
	int to, cost;
	edge(int to_, int cost_) : to(to_), cost(cost_) {}
};
typedef pair<int, int> P;
vector<edge> G[MAX_N];

void Dijkstra(int start) {
	fill(d, d + n, INF);
	priority_queue<P, vector<P>, greater<P>> que;
	d[start] = 0;
	que.push(P(0, start));

	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main()
{
	cin >> n;
	for (int i = 0, u, k; i < n; i++) {
		cin >> u >> k;
		for (int j = 0, v, c; j < k; j++) {
			cin >> v >> c;
			G[u].push_back(edge(v, c));
		}
	}
	Dijkstra(0);
	for (int i = 0; i < n; i++) {
		cout << i << ' ' << d[i] << endl;
	}
	return 0;
}