Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const (
	INFTY = 1 << 21
	NIL   = -1
)

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph [][]int

func (g *Graph) dikstra(n int) string {
	var (
		u, minv = 0, 0
	)

	d := make([]int, n)
	color := make([]int, n)

	for i := 0; i < n; i++ {
		d[i] = INFTY
		color[i] = WHITE
	}
	d[0] = 0
	color[0] = GRAY

	for {
		minv = INFTY
		u = -1
		for i := 0; i < n; i++ {
			if minv > d[i] && color[i] != BLACK {
				u = i
				minv = d[i]
			}
		}

		if u == -1 {
			break
		}

		color[u] = BLACK
		for v := 0; v < n; v++ {
			if color[v] != BLACK && (*g)[u][v] != INFTY {
				if d[v] > d[u]+(*g)[u][v] {
					d[v] = d[u] + (*g)[u][v]
					color[v] = GRAY
				}
			}
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d ", i))
		if d[i] == INFTY {
			out.WriteString(fmt.Sprintf("%d\n", -1))
			continue
		}
		out.WriteString(fmt.Sprintf("%d\n", d[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	g := make(Graph, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		for j := 0; j < n; j++ {
			g[i][j] = INFTY
		}
	}

	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())

		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			sc.Scan()
			c, _ := strconv.Atoi(sc.Text())

			g[u][v] = c
		}
	}

	return g.dikstra(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: #include<iostream>
#include<vector>
#include<queue>
#include<utility>
#include<climits>
#include<algorithm>
using namespace std;
typedef int Cost;
typedef int Node;

void dijkstra(int start,   vector<vector< pair<Node,Cost> > > m){
  vector<Cost> costs(m.size());
  bool visited[m.size()];

  fill(costs.begin(),costs.end(),INT_MAX);
  fill(visited,visited+m.size(),false);
  
  priority_queue<pair<Cost,Node> ,vector<pair<Cost,Node> >, greater<pair<Cost,Node> > > q;
  q.push(make_pair(0,start));
  while(!q.empty()){
    Cost c = q.top().first;
    Node n = q.top().second;
    q.pop();
    if(!visited[n]){
      costs[n] = c;
      for(auto &x:m[n]){
        int node = x.first;
        int cost = x.second;
        q.push(make_pair(cost+c,node));
      }
      visited[n] = true;
    }
  }
  for(int i = 0;i < costs.size();i++){
    cout << i << ' ' << costs[i] << endl;
  }
}

int main(){
  int n;
  cin >> n;
  vector<vector< pair<Node,Cost> > > m(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;
      m[u].push_back(make_pair(v,c));
    }
  }
  dijkstra(0,m);
}

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



using namespace std;



static const int INF = 999999;



int main(){

	int n,array[100][100];



	for(int i=0; i<100; i++){

		for(int j=0; j<100; j++){

			if(i==j) array[i][j]=0;

			else array[i][j]=INF;

		}

	}

	

	cin>>n;



	for(int i=0; i<n; i++){

		int u,k;

		cin>>u>>k;

		for(int j=0; j<k; j++){

			int t,c;

			cin>>t>>c;

			array[u][t]=array[t][u]=c;

		}

	}



	int d[100];

	fill(d,d+n,INF);

	d[0]=0;

	bool flag[100]={};



	while(1){

		int u=-1,infn=INF;

		for(int i=0; i<n; i++){

			if(!flag[i] && d[i]<=infn){

				u = i;

				infn = d[u];

			}

		}

		if(u==-1) break;

		flag[u] = true;



		for(int i=0; i<n; i++){

			if(array[u][i]!=INF && !flag[i]){

				d[i] = min(d[i],d[u]+array[u][i]);

			}

		}

	}



	for(int i=0; i<n; i++){

		cout<<i<<" "<<d[i]<<endl;

	}



	return 0;

}

C++: #include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

#define MAX_N 100
#define INF 100001

int cost[MAX_N][MAX_N];
int d[MAX_N];
bool used[MAX_N];
int V;

void dijkstra(int s) {
	fill_n(d, V, INF);
	fill_n(used, V, false);
	d[s] = 0;

	while (1) {
		int v = -1;
		for (int u = 0; u < V; u++)
			if (!used[u] && (v == -1 || d[u] < d[v]))
				v = u;

		if (v == -1)
			break;

		used[v] = true;

		for (int u = 0; u < V; u++)
			d[u] = min(d[u], d[v] + cost[v][u]);
	}
}

int main() {
	int n;
	cin >> n;
	V = n;
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		fill_n(cost[u], n, INF);
		for (int j = 0; j < k; j++) {
			int v, c;
			cin >> v >> c;
			cost[u][v] = c;
		}
	}
	dijkstra(0);
	for (int i = 0; i < n; i++) {
		cout << i << " " << d[i] << endl;
	}
	
	return 0;
}

C++: //By Vlgd
#include<bits/stdc++.h>
using namespace std;
const int INF=(1<<21);
const int N=100;
int G[N][N],n,vis[N]={0},dis[N];
void dij(int s){
	dis[s]=0;
	while(1){
		int min=INF,u=-1;
		for(int i=0;i<n;i++){
			if(!vis[i]&&min>dis[i]){
				min=dis[i];
				u=i;
			} 
		}
		if(u==-1) break;
		vis[u]=1;
		for(int v=0;v<n;v++)
			if(G[u][v]!=INF&&!vis[v])
				if(dis[v]>dis[u]+G[u][v]) 
					dis[v]=dis[u]+G[u][v];
	}
}
int main(){
	scanf("%d",&n);
	int u,v,deg,w;
	for (int i=0;i<n;i++){
		dis[i]=INF;
		for (int j=0;j<n;j++) G[i][j]=INF;
	}
	for (int i=0;i<n;i++){
		scanf("%d%d",&u,&deg);
		for (int j=0;j<deg;j++){scanf("%d%d",&v,&w);G[u][v]=w;}
	}
	dij(0);
	for (int i=0;i<n;i++) printf("%d %d\n",i,dis[i]);
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>

#define INF 2000000001
#define MAX 101
#define NIL -1

using namespace std;

typedef struct {
    int toid;
    int far;
} PATH;

vector<PATH> D[MAX];
int N;
int Dist[MAX];

void dijkstra(){//0??????????????¢??????????????£?????????
    
    bool complete[MAX];
    vector<int> S;
    
    for (int i = 0; i < N; i++) {
        complete[i] = false;
        Dist[i] = INF;
    }
 
    //???????¨????
    Dist[0] = 0;
    S.push_back(0);
    int u=0,minf;
    complete[u] = true;
    
    while (1) {
        if (S.size() == N) break;
        
        //????????????
        for (int j = 0; j < D[S[u]].size(); j++) {
            if (!complete[D[S[u]][j].toid] && Dist[S[u]] + D[S[u]][j].far < Dist[D[S[u]][j].toid]) {
                Dist[D[S[u]][j].toid] = Dist[S[u]] + D[S[u]][j].far;
            }
        }
        
        
        
        u = NIL;
        minf = INF;
        
        //?¨??????´??°
        for (int i = 0; i < S.size(); i++) {
            
            for (int j = 0; j < D[S[i]].size(); j++) {
                if (Dist[D[S[i]][j].toid] < minf && !complete[D[S[i]][j].toid]) {
                    minf = Dist[D[S[i]][j].toid];
                    u = D[S[i]][j].toid;
                }
            }
            
        }
        S.push_back(u);
        complete[u] = true;
        u = S.size()-1;//????????§u????????§??¨????????????????????????
    }
}

int main(){
    cin >> N;
    for (int i = 0; i < N; i++) {
        int bb1,bb2;
        cin >> bb1 >> bb2;
        for (int j = 0; j < bb2; j++) {
            PATH bb3;
            cin >> bb3.toid >> bb3.far;
            D[i].push_back(bb3);
        }
    }
    
    dijkstra();
    
    for (int i = 0; i < N; i++) {
        printf("%d %d\n",i,Dist[i]);
    }
    
    return 0;
}