Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

//make priority queue
type Item struct {
	id       int
	priority int // this state is priority and distans from start
	index    int
}

type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

// we want the ascending-priority-queue.
// So we use less than here.
func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = j
	pq[j].index = i
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1 //for safety
	*pq = old[0 : n-1]
	return item
}

func (pq *PriorityQueue) update(dist int, id int) {
	for _, i := range *pq {
		if i.id == id {
			if i.priority > dist {
				i.priority = dist
			}
		}
	}
}

// the main code
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func dikstra(dist [][]int, n int) []int {
	// preparate priority queue
	inf := 1 << 30
	pq := make(PriorityQueue, n)
	shortests := make([]int, n)
	for i := 0; i < n; i++ {
		pq[i] = &Item{
			id:       i,
			priority: inf,
			index:    i,
		}

		shortests[i] = inf
	}
	pq[0].priority = 0
	shortests[0] = 0
	heap.Init(&pq)

	for pq.Len() > 0 {
		item := heap.Pop(&pq).(*Item)
		shortests[item.id] = item.priority
		for id, d := range dist[item.id] {
			if d != -1 {
				pq.update(item.priority+d, id)
			}
		}
		heap.Init(&pq)
	}
	return shortests
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	// init
	n := nextInt(sc)
	dist := make([][]int, n)
	for i := 0; i < n; i++ {
		dist[i] = make([]int, n)
		for j := 0; j < n; j++ {
			dist[i][j] = -1
		}
	}

	// std Input
	for i := 0; i < n; i++ {
		u := nextInt(sc)
		k := nextInt(sc)
		for j := 0; j < k; j++ {
			v, c := nextInt(sc), nextInt(sc)
			dist[u][v] = c
		}
	}

	shortests := dikstra(dist, n)
	for i, d := range shortests {
		fmt.Printf("%d %d\n", i, d)
	}
}

C++: #include <stdio.h>
#include <iostream>
#include <queue>
#include <list>
using namespace std;

#define NODE_NUM 100

class Node
{
private:
	//int next_node_list[NODE_NUM];
	list<int> next_node_list;
	//int next_node_num;
	//int next_weight_list[NODE_NUM];
	list<int> next_weight_list;
public:
	Node();
	void AddNextNode(int id, int weight);
	void SetWeight(int weight);
	void DistributeWeight();
	int id;
	int weight_from_0;
	bool check;
};

Node::Node()
{
	//next_node_num = 0;
	weight_from_0 = -1;
	check = false;
}

Node *Node_list;

priority_queue<Node, vector<Node>, greater<Node> > que;
bool operator> (const Node &n1, const Node &n2){
	return n1.weight_from_0 > n2.weight_from_0;
};

void Node::AddNextNode(int id, int weight)
{
	//next_node_list[next_node_num] = id;
	next_node_list.push_back(id);
	//next_weight_list[next_node_num] = weight;
	next_weight_list.push_back(weight);
	//next_node_num++;
}

void Node::SetWeight(int weight)
{
	if (weight_from_0 == -1 || weight < weight_from_0) {
		weight_from_0 = weight;
	}
}

void Node::DistributeWeight()
{
	check = true;
	/*for (int i = 0; i < next_node_num; i++) {
		if (Node_list[next_node_list[i]].check == false) {
			Node_list[next_node_list[i]].SetWeight(weight_from_0 + next_weight_list[i]);
			que.push(Node_list[next_node_list[i]]);
		}
	}*/
	list<int>::iterator itr2 = next_weight_list.begin();
	for(list<int>::iterator itr = next_node_list.begin(); itr != next_node_list.end(); itr++){	
		if (Node_list[*itr].check == false) {
			Node_list[*itr].SetWeight(weight_from_0 + *itr2);
			que.push(Node_list[*itr]);
		}
		itr2++;
	}
}

int main(void)
{
	//input
	int n;
	cin >> n;
	Node_list = new Node[n]();
	for (int i = 0; i < n; i++) {
		Node_list[i].id = i;
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v, c;
			cin >> v >> c;
			Node_list[i].AddNextNode(v, c);
		}
	}

	//weight from 0 ?
	Node_list[0].check = true;
	Node_list[0].weight_from_0 = 0;
	Node_list[0].DistributeWeight();
	while (!que.empty()) {
		int id = que.top().id;
		que.pop();
		Node_list[id].DistributeWeight();
	}

	//output
	for (int i = 0; i < n; i++) {
		cout << i << " " << Node_list[i].weight_from_0 << endl;
	}
	
	return 0;
}

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;
}