Go: package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

const MAX = 100
const INFTY = math.MaxInt64
const WHITE = 0
const GRAY = 1
const BLACK = 2

var n int
var M [MAX][MAX]int

func dijkstra() {
	var minv int
	var d [MAX]int
	var color [MAX]int

	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 && M[u][v] != INFTY {
				if d[v] > d[u]+M[u][v] {
					d[v] = d[u] + M[u][v]
					color[v] = GRAY
				}
			}
		}

	}
	for i := 0; i < n; i++ {
		fmt.Printf("%v %v\n", i, d[i])
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ = strconv.Atoi(sc.Text())

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			M[i][j] = INFTY
		}
	}

	for i := 0; i < n; i++ {
		sc.Scan()
		f, _ := 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())
			M[f][v] = c
		}
	}
	dijkstra()
}

C++: // 単一始点最短経路 ( ダイクストラ法 )
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

#include<queue>

using namespace std;

static const int MAX_N = 100;
static const int INFTY = (1 <<21);

static const int NO = 0;
static const int YES = 1;

// グラフ情報を保持する配列
int ary_graph[MAX_N + 1][MAX_N + 1];
// 辺の関係を保持する配列
vector<int> v_connection[MAX_N];
// スタートからの距離を保持する配列
int ary_distance[MAX_N + 1];
// 各頂点の状態を保持する配列 ( 確定 or 未確定 )
int ary_vertex[MAX_N];

void Dijkstra_Method(int start_v, int all_v);

int main(void)
{

    int n, u, k, v, c;

    for(int i = 0; i < MAX_N + 1; i++)
    {
        ary_vertex[i] = NO;

        // 全頂点のスタートからの距離を無限大とする
        ary_distance[i] = INFTY;

        for(int j = 0; j < MAX_N + 1; j++)
        {
            // 配列の初期化
            ary_graph[i][j] = INFTY;
        }
    }

    cin >> n;

    for(int i = 0; i < n; i++)
    {
        cin >> u >> k;

        for(int j = 0; j < k; j++)
        {
            cin >> v >> c;

            // 隣接行列の設定
            ary_graph[u][v] = c;
            // 辺の関係の保存
            v_connection[u].push_back(v);
        }
    }

    Dijkstra_Method(0, n);

    // 結果の表示
    for(int i = 0; i < n; i++)
    {
        cout << i << " " << ary_distance[i] << endl;;
    }

    return 0;
}

// ダイクストラ法を実施する関数
// start_v : スタートする頂点のNo.
// all_v   : 全頂点の数
void Dijkstra_Method(int start_v, int all_v)
{
    int vertex_num = 0;
    int ele, confirm_v, tmp_distance;
    int min_distance, min_v;

    // スタート地点の距離はゼロとする
    ary_distance[start_v] = 0;
    // 確定した頂点を設定
    confirm_v = start_v;
    ary_vertex[confirm_v] = YES;

    // 全頂点のスタートからの距離が確定するまで, ループを継続する
    while( vertex_num != all_v )
    {

        min_v = INFTY;
        min_distance = INFTY;

        // 確定した頂点から, [直接つながっている] かつ [未確定]の頂点の距離を計算する
        for(int i = 0; i < v_connection[confirm_v].size(); i++)
        {
            // 辺のつながっている頂点No.
            ele = v_connection[confirm_v][i];

            // confirm_v の頂点を経由した場合の距離 ( 経由する頂点までの距離 + 辺の重み )
            tmp_distance = ary_distance[confirm_v] + ary_graph[confirm_v][ele];

            if( ary_vertex[ele] == NO )
            {
                // 未確定の頂点について検討する

                if( tmp_distance < ary_distance[ele] )
                {
                    // 最小値で距離情報を更新する
                    ary_distance[ele] = tmp_distance;
                }

                if( min_distance > tmp_distance )
                {
                    // confirm_v の頂点から, 最小距離の頂点を探す
                    min_distance = tmp_distance;
                    min_v = ele;
                }
            }
        }

        // 次に進むべき頂点の確定
        if( min_v != INFTY )
        {
            confirm_v = min_v;
            ary_vertex[confirm_v] = YES;
        }

        vertex_num++;

    }

    return;
}

C++: /*
* @Author: Samson
* @Date:   2018-06-14 14:39:51
* @Last Modified by:   Samson
* @Last Modified time: 2018-06-14 15:11:56
*/
//   @URL : http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_12_B
#include<bits/stdc++.h>
#include<algorithm>
#include<queue>
#include <cstdlib>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 1e5+10;

int n,color[105],d[105];
vector<pair<int,int> > a[105];

void dijkstra()
{
	priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > que;
	memset(color,0,sizeof color);
	memset(d,INF,sizeof d);
	d[0] = 0;
	que.push(make_pair(0,0));
	while(que.size())
	{
		pair<int,int> p = que.top();
		que.pop();
		int u = p.second;
		color[u] = 1;

		if(d[u] < p.first)	continue;

		for(int i = 0; i < a[u].size(); ++i)
		{
			int v = a[u][i].first;
			if(color[v])	continue;
			if(d[v] > d[u]+a[u][i].second)
			{
				d[v] = d[u]+a[u][i].second;
				que.push(make_pair(d[v],v));
			}
		}
	}
	for(int i = 0; i < n; ++i)
		cout<<i<<' '<< (d[i]==INF?-1:d[i])<<'\n';
}
int main(void)
{
	ios::sync_with_stdio(false); 
	//cin.tie(0);
	cin>>n;
	int u,k,v,w;
	for(int i = 0; i < n; ++i)
	{
		cin>>u>>k;
		for(int j = 0; j < k; ++j)
		{
			cin>>v>>w;
			a[u].push_back(make_pair(v,w));
		}
	}
	dijkstra();
	return 0;
}

C++: #include <iostream>

using namespace std;

//#define INT_MIN     (-2147483647 - 1) /* minimum (signed) int value */
//#define INT_MAX       2147483647    /* maximum (signed) int value */
#define  INT_MAX (1 << 21)

static const int MAX = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, m[MAX][MAX];

int prim()
{
	int color[MAX], p[MAX], d[MAX];
	int u, minv;

	for (int i = 0; i < n; ++i)
	{
		color[i] = WHITE;
		p[i] = -1;
		d[i] = INT_MAX;
	}

	d[0] = 0;

	while (1)
	{
		minv = INT_MAX;
		u = -1;
		for (int i = 0; i < n; ++i)
		{
			if (d[i] < minv && color[i] != BLACK)
			{
				u = i;
				minv = d[i];
			}
		}

		if (-1 == u)
			break;
		color[u] = BLACK;

		for (int i = 0; i < n; ++i)
		{
			if (m[u][i] < d[i] && color[i] != BLACK)
			{
				d[i] = m[u][i];
				p[i] = u;
				color[i] = GRAY;
			}
		}
	}

	int sum = 0;
	for (int i = 0; i < n; ++i)
	{
		if (p[i] != -1)
			sum += m[p[i]][i];
	}
	return sum;
}

void dijkstra()
{
	int minv;
	int d[MAX], color[MAX];

	for (int i = 0; i < n; ++i)
	{
		d[i] = INT_MAX;
		color[i] = WHITE;
	}

	d[0] = 0;
	color[0] = GRAY;

	while (1)
	{
		minv = INT_MAX;
		int u = -1;
		for (int i = 0; i < n; ++i)
		{
			if (d[i] < minv && color[i] != BLACK)
			{
				u = i;
				minv = d[i];
			}
		}

		if (-1 == u) break;
		color[u] = BLACK;

		for (int i = 0; i < n; ++i)
		{
			if (color[i] != BLACK && m[u][i] + d[u] < d[i])
			{
				d[i] = d[u] + m[u][i];
				color[i] = GRAY;
			}
		}
	}

	for (int i = 0; i < n; ++i)
		cout << i << " " << ((d[i] == INT_MAX) ? -1 : d[i]) << endl;
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			m[i][j] = INT_MAX;
		}
	}

	int k, c, u, v;
	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;
}