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 <vector>
#include <climits>
#include <queue>

using namespace std;

const int kSize = 100001;

vector<int> V;

struct Node {
    int to;
    int weight;

    Node(int _to, int _weight) {
        to = _to;
        weight = _weight;
    }
};

int n;
vector<Node> adj[kSize];
bool isMarked[kSize];
int tree[kSize];
int dis[kSize];

void Dijkstra(int s) {
    dis[s] = 0;
    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<> > pq;

    pq.push(make_pair(s, 0));
    isMarked[s] = true;
    tree[s] = s;

    while (!pq.empty()) {
        pair<int, int> p = pq.top();
        pq.pop();
        int from = p.first;
        for (int i = 0; i < adj[from].size(); ++i) {
            int to = adj[from][i].to;
            if (!isMarked[to]) {
                if (dis[from] + adj[from][i].weight < dis[to]) {
                    dis[to] = dis[from] + adj[from][i].weight;
                    tree[to] = from;
                    pq.push(make_pair(to, dis[to]));
                }
            }
        }
    }
}

int main() {
    fill(isMarked, isMarked + kSize, false);
    fill(dis, dis + kSize, INT_MAX);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            int v, c;
            cin >> v >> c;
            adj[u].emplace_back(v, c);
        }
    }

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

C++: #include <bits/stdc++.h>
using namespace std;
#define INFTY (1<<30)

int n;
vector<int> color(101,0),d(101,INFTY),p(101);
vector<vector<int>> M(101,vector<int>(101,INFTY));

void dijkstra(int s){
    d[s]=0;
    p[s]=-1;
    while(1){
        int u;
        int mincost=INFTY;
        for(int i=0;i<n;i++){
            if(color[i]!=2&&d[i]<mincost){
                mincost=d[i];
                u=i;
            }
        }
        if(mincost==INFTY) break;
        color[u]=2;
        for(int v=0;v<n;v++){
            if(color[v]!=2&&M[u][v]!=INFTY){
                if(d[u]+M[u][v]<d[v]){
                    d[v]=d[u]+M[u][v];
                    p[v]=u;
                    color[v]=1;
                }
            }
        }
    }
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b,c,k;
        cin>>a>>k;
        for(int j=0;j<k;j++){
            cin>>b>>c;
            M[a][b]=c;
        }
    }

    dijkstra(0);

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

C++: 
#include<bits/stdc++.h>

using namespace std;

const int maxn=1e2+5;
const int inf=(1<<21);
const int white=0;
const int gray=1;
const int black=2;

int n,m[maxn][maxn];

void dijkstra()
{
    int minv,d[maxn],book[maxn];
    for(int i=0;i<n;i++){
        d[i]=inf;
        book[i]=0;
    }
    d[0]=0;
    while(1){
        minv=inf;
        int u=-1;
        for(int i=0;i<n;i++){
            if(minv>d[i]&&book[i]==0){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1){
            break;
        }
        book[u]=1;
        for(int v=0;v<n;v++){
            if(book[v]==0&&(d[v]>d[u]+m[u][v])){
                    d[v]=d[u]+m[u][v];
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<i<<" "<<(d[i]==inf?-1:d[i])<<endl;
    }
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            m[i][j]=inf;
        }
    }
    int u,k,v,c;
    for(int i=0;i<n;i++){
        cin>>u>>k;
        for(int j=0;j<k;j++){
            cin>>v>>c;
            m[u][v]=c;
        }
    }
    dijkstra();
    return 0;
}
/*
5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3 
*/

C++: #include <iostream>
using namespace std;
static const int Max = 100;
static const int Inf = 100000000; // ??????
static const int Nil = -1; // 

enum Status {
	Not_Searched = 0,
	Connected = 1,
	Searched = 2
};

int n;
int M[Max][Max] = {};
Status st[Max] = {}; 
int min_cost[Max] = {}; // min cost of point from start
//int parent[Max] = {}; // ??????index

void dijkstra() {
	for (int i = 0; i < n; i++) {
		min_cost[i] = Inf;
	}

	min_cost[0] = 0;
	st[0] = Connected;
	while (1) {
		int mincost = Inf;
		int min_index = Nil;
		for (int i = 0; i < n; i++) {
			if (st[i] != Searched && mincost > min_cost[i]) {
				mincost = min_cost[i];
				min_index = i;
			}
		}
		if (min_index == Nil) break;
		// index ?????????????????????????????????
		st[min_index] = Searched;
		for (int i = 0; i < n; i++) {
			// min_index ??¨???????????£??????????????????????????????????????????
			if (st[i] != Searched && M[min_index][i] != Inf) {
				if (min_cost[i] > min_cost[min_index] + M[min_index][i]) {
					min_cost[i] = min_cost[min_index] + M[min_index][i];
					st[i] = Connected;
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << i << " " << (min_cost[i] == Inf ? -1 : min_cost[i]) << endl;
	}
	return;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			M[i][j] = Inf;
		}
	}
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int vi, ci;
			cin >> vi >> ci;
			M[i][vi] = ci;
		}
	}
	dijkstra();
	return 0;
}