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 <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#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 ll inf = 99900100100;
const int MOD = 998244353;
const double EPS = 1e-9;

vector<vector<pair<int,int> > > G(1100);

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n){
      int u,k;
      cin >> u >> k;
      rep(j,k){
        int v,c;
        cin >> v >> c;
        G[u].push_back(mp(v,c));
      }
    }
    ll d[1100] = {};
    rep(i,1100) d[i] = inf;
    d[0] = 0LL;
    while(true){
        bool update = false;
        rep(i,n){
          for(auto o : G[i]){
            if(d[o.fi] > d[i]+o.se){
                d[o.fi] = d[i]+o.se;
                update = true;
            }
          }
        }
        if(!update) break;
    }
    rep(i,n) cout << i << " " << d[i] << endl;
    return 0;
}

C++: #include<iostream>
using namespace std;
static const int INF=(1<<21);
static const int WHI=0;
static const int BLA=2;
static const int GR=1;

int n,M[100][100];

void dijkstra(){
  int minv;
  int a[100],color[100];
  for (int i=0;i<n;i++){
    a[i]=INF;
    color[i]=WHI;
  }

  
  color[0]=GR;
  a[0]=0;
  while(1){
    minv=INF;
    int e =-1;
    for (int i=0;i<n;i++){
      if(minv>a[i]&&color[i]!=BLA){
	minv=a[i];
	e=i;
      }
    }
    
    if(e==-1)break;
    color[e]=BLA;
    for(int v=0;v<n;v++){
      if(color[v]!=BLA && M[e][v]!=INF){
	if(a[v]>a[e]+M[e][v]){
	  a[v]=a[e]+M[e][v];
	  color[v]=GR;
	}
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<i<<" "<<(a[i]==INF ? -1 : a[i]) << endl;
  }
}

int main(){
  int k,m,e,v;
  
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      M[i][j]=INF;
    }
  }
  for(int i=0;i<n;i++){
    cin>>e>>k;
    for(int j=0;j<k;j++){
      cin>>v>>m;
      M[e][v]=m;
      
    }
  }
  dijkstra();
}

C++: #include<iostream>
#define INF 1<<21
using namespace std;
static const int N = 101;
int n,A[N][N];
void dikstra(void){
    int d[N],p[N],color[N],minv;
    for(int i=0;i<n;i++){
        d[i] = INF;
        p[i] = -1;
        color[i] = 0;
    }
    d[0] = 0;
    while(1){
        int u =-1;
        minv = INF;
        for(int i=0;i<n;i++){
            if(d[i]<minv && color[i]!=1){
                u = i;
                minv = d[i];
            }
        }
        if(u==-1){
            break;
        }
        color[u] = 1;
        for(int v=0;v<n;v++){
            if(d[u]+ A[u][v] < d[v]){
                d[v] = d[u] + A[u][v];
                p[v] = u;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout << i << ' ' << d[i] << endl;
    }
}
int main(void){
    int u,adj,v;
    cin >> 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++){
        cin >> u >> adj;
        for(int j=0;j<adj;j++){
            cin >> v >> A[u][v];
        }
    }
    dikstra();
    return 0;
}

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

static const int  MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[MAX][MAX];

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

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

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

    while(1)
    {
        minv = INFTY;
        int 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(int 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++)
    {
        cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }


}

int main()
{
  int e;
  int i,j;
  
 cin >>n;

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

    int k,c,u,v;

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