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 <cstring>
using namespace std;

const int Max = 105;
const int INF = (1<<29);
int n, G[Max][Max], Min, color[Max], d[Max], p[Max];
int u, k, v, c;

void dijstra()
{
    memset(color, -1, sizeof(color));
    for(int i=0; i<n; i++)
    {
        d[i] = INF;
    }
    d[0] = 0;
    p[0] = -1;
    while(1)
    {
        int minv = INF, u;
        for(int i=0; i<n; i++)
        {
            if(color[i]!=0 && d[i]<minv)
            {
                minv = d[i];
                u = i;
            }
        }
        if(minv==INF) break;
        color[u] = 0;

        for(int j=0; j<n; j++)
        {
            if(color[j]!=0 && G[u][j]!=INF && d[u]+G[u][j]<d[j])
            {
                d[j] = G[u][j]+d[u];
                p[j] = u;//j的父节点为u，有利于重建MST
            }
        }
    }
    //打印输出
    for(int i=0; i<n; i++)
    {
        cout << i << " " << d[i] << endl;
    }
}

int main()
{
    cin >> n;
    Min = 0;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            G[i][j] = INF;
        }
    }
    for(int i=0; i<n; i++)
    {
         cin >> u >> k;
         for(int i=0; i<k; i++)
         {
             cin >> v >> c;
             G[u][v] = c;//化为邻接矩阵
         }
    }
    dijstra();
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<climits>
#define INF INT_MAX
using namespace std;
int n;
int A[1000][1000];
int d[1000];
bool used[1000];
int D[1000][1000];

void Init(int f){
  for(int i=0;i<f;i++){
    for(int j=0;j<f;j++)D[i][j] = INF;
  }

}

void djkstra(){
  for(int i=0;i<n;i++){
    d[i] = INF;
    used[i] = false;
  }
  d[0] = 0;

  while(true){
    int v = -1;
    for(int i=0;i<n;i++){
      if(!used[i] && (v == -1 || d[v] > d[i]))v = i;
    }
    if(v == -1)break;
    used[v] = true;
    for(int i=0;i<n;i++){
      d[i] = min(d[i],d[v] + D[v][i]);
    }
  }
}



int main(){
  scanf("%d",&n);
  int u,k,C,V;
  Init(n);
 
  for(int i=0;i<n;i++){
      scanf("%d %d",&u,&k);     
      for(int j=0;j<k;j++){
	scanf("%d %d",&V,&C);
	D[u][V] = C;
	D[V][u] = C;
      }     
  }
  
  //for(int i=0;i<n;i++)D[i][i] = 0;
  //for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j] = min(D[i][j],D[i][k] + D[k][j]);

  djkstra();
 
  for(int i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)
const int INF=1000000000;

using Graph=vector<vector<int>>;

int n;
vector<int> d;

void Dijkstra(const Graph &G){
    // 暫定の最短距離，頂点番号
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> que;
    que.emplace(d[0],0);

    // 距離を確定すべき頂点がなくなるまで続ける
    while(!que.empty()){
        pair<int,int> p=que.top();
        que.pop();
        int v=p.second;
        
        // 最短距離より大きい場合は無視
        if(d[v]<p.first) continue;

        REP(i,n){
            // 辺(v,i)がなければ無視
            if(G[v][i]==INF) continue;

            // 辺(v,i)を採用して距離が短くなるならば，暫定的に採用
            if(d[i]>d[v]+G[v][i]){
                d[i]=d[v]+G[v][i];
                que.emplace(d[i],i);
            }
        }
    }
}

int main(){
    cin>>n;

    // グラフの受け取り
    Graph G(n,vector<int>(n));
    REP(i,n){
        int u,k;
        cin>>u>>k;
        G[u].assign(n,INF);
        REP(j,k){
            int v,c;
            cin>>v>>c;
            G[u][v]=c;
        }
    }

    // d[i]=(無限大) で初期化
    d.assign(n,INF);
    d[0]=0;

    Dijkstra(G);

    REP(i,n){
        cout<<i<<" "<<d[i]<<endl;
    }
}

C++: #include <iostream>

using namespace std;
int M[100][100]; //?????\??????
int n; //n?????¶?????°
static const int WHITE=0; //?????????????????°
static const int GRAY=1; //??°??????????????°
static const int BLACK=2; //????????????????????\
static const int INFTY=(1<<21);  //??£??¨??£??????
void dijkstra()
{
    int color[100];  //????????¶???????¢????
    int d[100]; //????????¶????????????????°?????????????????????????T??????????????????
    for(int i=0;i<n;i++)
       {
          d[i]=INFTY;  //???????§??????¶?????????????????????????????????????§?????????£??????
          color[i]=WHITE;
       }
    d[0]=0; //???????????????????????????d???0
    while(1)
    {
        int r=-1;int minv=INFTY;
        //?????°??????????°????????????\??°??????T???
        for(int i=0;i<n;i++)
        {
            if(color[i]!=BLACK&&d[i]<minv)
            {
                r=i;minv=d[i];
            }
        }
        if(r==-1) break; //?????????????????¶???-1????????´????????????????????????????????????????????????
        color[r]=BLACK; //?????????????°?????????\??????T??????????°±???????????¶??????BLACK
        //?????¶??????T????????°??????????????\?????´??°??????????????¶???
        //??´??°??¶????????¶??????????????°????????£??????????????\????????¶???????????´??°??????
        for(int i=0;i<n;i++)
        {
            if(color[i]!=BLACK&&M[r][i]!=INFTY) //?????????????????\?????????????????????
            {
                if(d[i]>M[r][i]+d[r]) //?????????????????????
                {
                    d[i]=M[r][i]+d[r];
                    color[i]=GRAY;
                }
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        cout<<i<<" "<<(d[i]==INFTY?-1:d[i])<<endl;
    }
}
int main()
{
    while(cin>>n)
    {
        //????§?????????\??????
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                M[i][j]=INFTY;
        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;
}