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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <utility>
using namespace std;
//_____
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define err(...) fprintf(stderr, __VA_ARGS__)
#define show(x) cerr << #x << ':' << x << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
const int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};
#define INF 0x3f3f3f3f
#define LEN 1000011
#define NIL -1
//_______

int N;
vector <pii> G[101];
int mcos[101];

void dijkstra(int s)
{
   priority_queue < pii, vector<pii>, greater<pii> > pq;
   pq.push( mkp(0, s) );
   memset( mcos, INF, sizeof(mcos) );
   mcos[s] = 0;

   while( !pq.empty() ){
      const pii tmp = pq.top(); pq.pop();
      if( mcos[tmp.se] < tmp.fi )continue;

      for( const auto& v : G[tmp.se] ){
         const int nc = v.fi + tmp.fi;
         if( chmin( mcos[v.se], nc )) pq.push( mkp(nc, v.se) );
      }
   }
   return ;
}

signed main()
{
   FAST();
   cin >> N;
   rep(i, N){
      int u, k, to, c;
      cin >> u >> k;
      while(k--){
         cin >> to >> c;
         G[i].pb( mkp(c,to) );
      }
   }
   dijkstra(0);
   rep(i, N){
      cout << i << ' ' << mcos[i] << '\n';
   }
}

C++: #include<iostream>
#include<string>
using namespace std;

void dijkstra(int s);
const int Infty = 20000000;

int **M,*d,*p,n;
string *color;

int main(){
	cin>>n;
	M = new int*[n]; for(int i=0;i<n;i++) M[i] = new int[n];
	d = new int[n]; p = new int[n]; color = new string[n];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++) M[i][j] = -1;
	}

	for(int i=0;i<n;i++){
		int vertex,deg,e,w;
		cin>>vertex>>deg;
		for(int j=0;j<deg;j++){
			cin>>e>>w;
			M[i][e]  = w;
		}
	}

	dijkstra(0);

	for(int i=0;i<n;i++) delete [] M[i]; delete [] M;
	delete [] d; delete [] p; delete [] color;
}

void dijkstra(int s){
	for(int i=0;i<n;i++){
		d[i] = Infty; color[i] = "WHITE";
	}
	d[s] = 0; p[s] = -1;

	while(true){
		int u , mindist = Infty;
		for(int i=0;i<n;i++){
			if(color[i]!="BLACK" && d[i]<mindist){
				mindist = d[i];
				u = i;
			}
		}

		if(mindist==Infty) break;

		color[u] = "BLACK";

		for(int v=0;v<n;v++){
			if(color[v]!="BLACK" && M[u][v]!=-1){
				if(d[u]+M[u][v]<d[v]){
					d[v] = d[u]+M[u][v];
					p[v] = u;
					color[v] = "GRAY";
				}
			}
		}
	}

	for(int i=0;i<n;i++)
		cout<<i<<" "<<d[i]<<endl;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
constexpr auto INF = 2147483647;
typedef long long ll;

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

int n, Adj_Marix[MAX][MAX];

void dijkstra(){
  int minv;
  int distance[MAX], color[MAX];
  //init
  for(int i=0;i<n; i++){
    distance[i] = INF;
    color[i] = WHITE;
  }
  distance[0] = 0;
  color[0] = GRAY;
  while(1){
    minv = INF;
    int u  = -1;
    // Find next point
    for(int i =0; i<n; i++){
      if( minv > distance[i] && color[i] != BLACK){
        u = i;
        minv = distance[i];
      }
    }
    //if cant find next point
    if(u == -1) break;
    // Refresh dictance for adj points
    color[u] = BLACK;
    for(int v=0; v<n; v++){
      if(color[v] != BLACK && Adj_Marix[u][v] != INF){
        if(distance[v] > distance[u] + Adj_Marix[u][v]){
          distance[v] = distance[u] + Adj_Marix[u][v];
          color[v] = GRAY;
        }
      }
    }
  }
  for(int i =0; i<n; i++){
    cout << i << " " << (distance[i] == INF ? -1: distance[i] ) << endl;
  }
}

int main(){

  cin >> n;
  rep(i,n){
    rep(j,n){
      Adj_Marix[i][j] = INF;
    }
  }

  int k, c, u, v;
  rep(i,n){
    cin >> u >> k;
    rep(j,k){
      cin >> v >> c;
      Adj_Marix[u][v] = c;
    }
  }

  dijkstra();

  return 0;
}