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++: ///
// File:  alds1_12_b.cpp
// Author: ymiyamoto
//
// Created on Wed Oct 18 21:59:56 2017
//

#include <cstdint>
#include <iostream>

using namespace std;
#define SIZE 100
static int64_t graph[SIZE][SIZE];
static int64_t costs[SIZE];
static bool visited[SIZE];

static void dikstra(uint32_t n)
{
  costs[0] = 0;

  while (true) {
    int32_t min_index = -1;
    int64_t min_cost = INT32_MAX;

    for (uint32_t i = 0; i < n; i++) {
      if (!visited[i] && costs[i] < min_cost) {
        min_cost = costs[i];
        min_index = i;
      }
    }

    if (min_index == -1) break;

    visited[min_index] = true;

    for (uint32_t i = 0; i < n; i++) {
      if (graph[min_index][i] != -1) {
        if (costs[min_index] + graph[min_index][i] < costs[i]) {
          costs[i] = costs[min_index] + graph[min_index][i];
        }
      }
    }
  }
}

int32_t main()
{
  uint32_t n;
  cin >> n;

  for (uint32_t i = 0; i < n; i++) {
    for (uint32_t j = 0; j < n; j++) {
      graph[i][j] = -1;
    }
    costs[i] = INT32_MAX;
  }

  for (uint32_t i = 0; i < n; i++) {
    uint32_t id, k;
    cin >> id >> k;
    for (uint32_t j = 0; j < k; j++) {
      int64_t v, c;
      cin >> v >> c;
      graph[id][v] = c;
    }
  }

  dikstra(n);

  for (uint32_t i = 0; i < n; i++) {
    cout << i << " " << costs[i] << endl;
  }

  return 0;
}

C++: #include<stdio.h>
#include<limits.h>

#define rep( i ,end ) for( int i = 0 ; i < end ; ++i )
#define Nmax 100
#define INF ( INT_MAX / 10 )

int Node[ Nmax ][ Nmax ] ;

int min( int a ,int b )
{
	return a > b ? b : a ;
}

void Init( int NODE[ Nmax ][ Nmax ] ,int N )
{
	rep( i ,N )
	{
		rep( j ,N )
		{
			NODE[ i ][ j ] = ( i == j ) ? 0 : INF ;
		}
	}
}



int main( void )
{
	int N ,V ,K ;
	int v ,cost ;
	scanf( "%d" ,&N ) ;

	Init( Node ,N ) ;

	rep( i ,N )
	{
		scanf( "%d %d" ,&V ,&K ) ;

		rep( j ,K )
		{
			scanf( "%d %d" ,&v ,&cost ) ;

			Node[ V ][ v ] = cost ;
		}
	}

	rep( u ,N )
	{
		rep( i ,N )
		{
			rep( j ,N )
			{
				Node[ i ][ j ] = min( Node[ i ][ j ] ,Node[ i ][ u ] + Node[ u ][ j ] ) ;
			}
		}
	}

	rep( u ,N )
	{
		printf( "%d %d\n" ,u ,Node[ 0 ][ u ] ) ;
	}

	return 0 ;
}

C++: #include<iostream>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<climits>
#include<queue>
using namespace std;
#define int long long
vector<double> dijk(vector<tuple<int,int,double>> edge_list, int start){
        const int DJMAX = INT_MAX;
        set<int> node_list;
        for(auto edge : edge_list){
                node_list.insert(get<0>(edge));
                node_list.insert(get<1>(edge));
        }
        int nodenum = *node_list.rbegin()+1;
        vector<vector<double>> cost_map(nodenum, vector<double>(nodenum, DJMAX));
        for(auto edge : edge_list){
                cost_map[get<0>(edge)][get<1>(edge)] = get<2>(edge);
                cost_map[get<1>(edge)][get<0>(edge)] = get<2>(edge);
        }
        vector<double> cost(nodenum,DJMAX);
        cost[start] = 0;
        vector<int> visited(nodenum,0);
        priority_queue<pair<int,int>> que;
        que.push(pair<double,int>(0,start));
        while(!que.empty()){
                int s = que.top().second;
                que.pop();
                visited[s] = 1;
                for(int j=0;j<nodenum;j++){
                        if(visited[j]==1) continue;
                        double nc = cost[s]+cost_map[s][j];
                        if(nc<cost[j]){
                                cost[j] = nc;
                                que.push(pair<double,int>(-cost[j],j));
                        }
                }
        }
        return cost;
}
signed main(){
        int n;
        cin >> n;
        vector<tuple<int, int, double>> edges;
        for(int i=0;i<n;i++){
                int vs, vn;
                cin >> vs >> vn;
                for(int j=0;j<vn;j++){
                        int vt,c;
                        cin >> vt >> c;
                        edges.push_back(tuple<int,int,double>(vs,vt,c));
                }
        }
        auto ans = dijk(edges, 0);
        for(int i=0;i<n;i++){
                cout << i << " " << ans[i] << endl;
        }
        return 0;
}