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<iostream>
#include<algorithm>
#include<vector>
using namespace std;

const int INF = 0xfffffff;
const int MAX = 100;

struct Edge {
	int v;
	int c;
};

int main() {
	int n;
	vector<Edge> graph[MAX];
	int table[MAX];
	bool check[MAX];

	cin >> n;
	for (int i = 0; i < n; i++) {
		table[i] = INF;
		check[i] = false;
	}

	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			Edge e;
			cin >> e.v >> e.c;
			graph[u].push_back(e);
		}
	}

	int u = 0;
	table[0] = 0;
	while (true) {
		check[u] = true;

		for (int i = 0; i < graph[u].size(); i++) {
			int v = graph[u][i].v;
			int c = graph[u][i].c;
			if (table[v] > c + table[u]) {
				table[v] = c + table[u];
			}
		}

		int m = INF;
		int prev = u;
		for (int i = 0; i < n; i++) {
			if (check[i])continue;
			if (table[i] < m) {
				m = table[i];
				u = i;
			}
		}
		if (u == prev)break;
	}

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

	return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr<<#x<<": "<<x<<'\n'

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct Edge{
    int to;
    int cost;
}
vector<int> G[110];
int d[110] = {};
int main(){
    int n;
    cin >> n;
    rep(i,n){
        int t,m;
        cin >> t >> m;
        rep(j,m){
            int a,b;
            cin >> a >> b;
            G[t].push_back({a,b})
        }
    }

    rep(i,n) d[i] = 900010000;
    d[0] = 0;
    while(true){
        bool update = false;
        rep(i,n){
            for(const auto& e: G[i]){
                if(d[i] + e.cost < d[e.to]){
                    d[e.to] = d[i]+e.cost;
                    update = true;
                }
            }
        }
        if(!update) break;
    }

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

    return 0;
}

C++: #include<stdio.h>

#define N 100
#define BLACK 0
#define WHITE 1
#define INF 100000000
#define NIL -1

void dijkstra(void);

int A[N][N],n;

int main()
{
  int u,k,v,c;

  scanf("%d",&n);

  for(int i = 0; i < n; i++)
  {
    for(int j = 0; j < n; j++)
    {
      A[i][j] = INF;
    }
  }

  for(int i = 0;i < n; i++)
  {
    scanf("%d%d",&u,&k);
    for(int j = 0; j < k; j++)
    {
      scanf("%d%d",&v,&c);
      A[u][v] = c;
    }
  }

  dijkstra();

  return 0;
}

void dijkstra()
{

  int u,mincost;
  int d[N],pi[N],color[N];

  for(int u = 0; u < n; u++)
  {
    d[u] = INF;
    pi[u] = NIL;
    color[u] = WHITE;
  }

  d[0] = 0;

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

    color[u] = BLACK;

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

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

}

C++: #include <iostream>
using namespace std;
 
#define WHITE 0 
#define GRAY 1
#define BLACK 2
#define INFTY 10000000
int n,color[100],M[100][100],d[100],p[100];
int i,j,u,k,v,c;
 
//ダイクストラ法
void dijkstra(){

  //初期化
  for( i = 0; i < n; i++ ){
    color[i] = WHITE;
    d[i] = INFTY;
  }
  d[0] = 0;
  p[0] = -1;

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

    color[u] = BLACK;
 
    //更新
    for( v = 0; v < n; v++ ){
      if( color[v] != BLACK && M[u][v] != INFTY ){
	if( d[u] + M[u][v] < d[v] ){
	  d[v] = d[u] + M[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
    }
  }
  
  //出力
  for( i = 0; i < n; i++ ){
    cout << i << " ";
    if( d[i] == INFTY ) cout << -1;
    else cout << d[i];
    cout << endl;
  }
}
 
int main(){

  //入力
  cin >> n;
  for( i = 0; i < n; i++ ){
    for( j = 0; j < n; j++ ){
      M[i][j] = INFTY;
    }
  }
 
  for( i = 0; i < n; i++ ){
    cin >> u >> k;
    for( j = 0; j < k; j++ ){
      cin >> v >> c;
      M[u][v] = c;
    }
  }
   
  dijkstra();
 
  return 0;
}