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<bits/stdc++.h>
using namespace std;
#define MAX 100

int n;
long d[MAX], C[MAX][MAX];
vector<int> M[MAX];

struct Edge{
    int u;
    Edge(int u): u(u){}
    bool operator < (const Edge &e) const {
        if(d[u] != d[e.u]) return d[u] < d[e.u];
        else return u < e.u;
    }
};

void dijkstra(){
    bool seen[n], todo[n];
    list<Edge> E;
    fill(seen, seen + n, false);
    fill(todo, todo + n, false);
    seen[0] = true;
    E.push_front(Edge(0));
    
    while(!E.empty()){
        E.sort();
        int u = E.begin()->u;
        seen[u] = true;
        E.pop_front();
        vector<int>::iterator it;
        
        for(it = M[u].begin(); it != M[u].end(); it++){
            int v = *it;
            if(!seen[v]) d[v] = min(d[v], d[u] + C[u][v]);
            if(!seen[v] && !todo[v]){
                E.push_back(Edge(v));
                todo[v] = true;
            }
        }
    }
    return;
}

int main(){
    cin >> n;
    fill(d, d + n, LONG_MAX);
    d[0] = 0;
    for(int i = 0; i < n; i++){
        fill(C[i], C[i] + n, LONG_MAX);
        int u, q, v, cost;
        cin >> u >> q;
        for(int j = 0; j < q; j++){
            cin >> v >> cost;
            C[u][v] = cost;
            M[u].push_back(v);
        }
    }
    dijkstra();
    for(int i = 0; i < n; i++)
        cout << i << " " << d[i] << endl;
    return 0;
}

C++: #include<iostream>
#define INF 1e9
using namespace std;

int n,mp[101][101],D[101];
void dijkstra(){
  bool used[101]={};
  for(int i=0;i<101;i++)D[i]=INF;
  D[0]=0;
 
  while(1){
    int cost=INF,pos=-1;
    for(int i=0;i<n;i++) if(!used[i]&&D[i]<cost) pos=i,cost=D[i];//もし使用していなくて格納されているものよりコストが大きれればpositionをずらし、コストに今入っているDを入れる
    if(pos==-1)return ;
    used[pos]=1;//positionをずらしたら見たことになるので１に書き換える    
    for(int i=0;i<n;i++)D[i]=min(D[i],cost+mp[pos][i]);
  }
}

int main(){
     cin>>n;
  for(int i=0;i<101;i++)
    for(int j=0;j<101;j++) mp[i][j]=INF;
   
  for(int i=0,a,m;i<n;i++){
    cin>>a>>m;//aが頂点mが次数
    for(int j=0,b,c;j<m;j++)cin>>b>>c,mp[a][b]=c;
  }
  dijkstra();
  for(int i=0;i<n;i++)cout <<i<<" "<<D[i]<<endl;
   
  return 0;
}

C++: #include<iostream>
using namespace std;
#define INF 100000
int m[100][100]; //adjacency matrix
int n; //vertexes
void dijkstra();
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; //number
        int k; //output orders
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v; //vertex
            int c; //weight
            cin >> v >> c;
            m[u][v] = c;
        }
    }
    dijkstra();
    return 0;
}
void dijkstra() {
    int d[100]; //minimum cost
    int p[100]; //top parent
    d[0] = 0;
    p[0] = 1;
    for (int i = 1; i < n; i++) {
        p[i] = 0;
        d[i] = INF;
    }
    while (1) {
        int minv = INF;
        int u = -1;
        for (int i = 0; i < n; i++) {
            if (minv > d[i] && p[i] != 2) { //firstly only d[0]
                u = i; //tmp parent
                minv = d[i]; //min cost of 0 to i
            }
        }
        if (u == -1) {
            break;
        }
        p[u] = 2; //決まったら
        for (int v = 0; v < n; v++) {
            if (m[u][v] != INF && p[v] != 2) { //u and v are connected
                if (d[v] > d[u] + m[u][v]) {
                    d[v] = d[u] + m[u][v]; //get smaller cost
                    //ここでd[v]がINFから解放され、次の親になれる
                    p[v] = 1;
                }
            }
        }
    }
    for (int i = 0; i < n; i++) {
        cout << i << " ";
        if (d[i] == INF) {
            cout << -1 << endl;
        } else {
            cout << d[i] << endl;
        }
    }
}

C++: #include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#define P pair<int, int>

using namespace std;
const int MAX = 1<<30;

int main(){
  int n, d[109];
  vector<P> G[109];
  queue<int> Q;
  cin >> n;
  for(int i=0;i<n;i++){
    int u, k, v, c;
    cin >>u >> k;
    for(int j=0;j<k;j++){
      cin >> v >> c;
      G[u].push_back(P(v, c));
    }
    d[i] = MAX;
  }
  d[0] = 0;
  Q.push(0);
  while(!Q.empty()){
    int cur = Q.front();Q.pop();
    for(int i=0;i<G[cur].size();i++){
      int next = G[cur][i].first, weight = G[cur][i].second;
      if(weight + d[cur]< d[next]){
        d[next] = weight + d[cur];
        Q.push(next);
      }
    }
  }
  for(int i=0;i<n;i++)cout << i << ' ' << d[i] << endl;
}