Go: package main

import (
	"fmt"
	"container/heap"
)

type Node struct {
	Id int
	Dis int
}

type PriorityQueue []*Node

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

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dis < pq[j].Dis
}

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

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(*Node))
}

func (pq *PriorityQueue) Pop() interface{} {
	n := len(*pq)
	pop := (*pq)[n-1]
	*pq = (*pq)[0:n-1]
	return pop
}

func main() {
	var n int
	fmt.Scan(&n)

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
			fmt.Scan(&c[u][j])
		}

		if u == 0 {
			d[u] = 0
		} else {
			d[u] = 1 << 30
		}
		pq.Push(&Node{u, d[u]})
	}
	heap.Init(&pq)

	for pq.Len() > 0 {
		node := heap.Pop(&pq).(*Node)
		for i := 0; i < len(g[node.Id]); i++ {
			nextId := g[node.Id][i]
			nextDis := node.Dis + c[node.Id][i]
			if nextDis < d[nextId] {
				d[nextId] = nextDis
				heap.Push(&pq, &Node{nextId, nextDis})
			}
		}
	}

	for i := 0; i < n; i++ {
		fmt.Println(i, d[i])
	}
}

C++: #include <stdio.h>
#define INF 1000000
#define white 0
#define black 2
#define gray 1

int n,M[100][100];

void dijkstra();

int main(){
  int i,j,k,c,v,u;
  scanf("%d",&n);
  for(i=0;i<n;i++){ 
    for(j=0;j<n;j++){
      M[i][j]=INF;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      M[u][v]=c;
    }
  }
  dijkstra();
  
  return 0;
}
void dijkstra(){
  int i,d[100],mincost,color[100],v,u;
  for(i=0;i<n;i++){
    d[i]=INF;
    color[i]=white;
  }
  d[0]=0;
  color[0]=gray;

  while(1){
    mincost=INF;
    u=-1;
    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]!=INF){
	if(d[v]>d[u]+M[u][v]){
	  d[v]=d[u]+M[u][v];
	  color[v]=gray;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d ",i);
    if(d[i]==INF)printf("-1");
    else printf("%d",d[i]);
    printf("\n");
  }
}

C++: //#include <bits/stdc++.h>
#include<iostream>
#include<math.h>
using namespace std;

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
int INF = (1<<21);

void dijkstra(void);

int n;
int M[MAX][MAX];

int main(){
  int i,j;
  int c,k,u,v;
  cin >> n;
  for( i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      //M[i][j] = INFINITY;
      M[i][j] = INF;
    }
  }
  for(i = 0; i < n; i++){
    cin >> u;
    cin >> k;
    for(j = 0; j < k; j++){
      cin >> v;
      cin >> c;
      M[u][v] = c;
    }
  }
  dijkstra();
  return 0;
}

void dijkstra(){
  int minV;
  int d[MAX],color[MAX];
  int u,v;
  int i;
  for(i = 0; i < n; i++){
    //d[i] = INFINITY;
    d[i] = INF;
    color[i] = WHITE;
  }
  d[0] = 0;
  color[0] = GRAY;
  while(1){
    //minV = INFINITY;
    minV = INF;
    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(v = 0; v < n; v++){
      //if(color[v] != BLACK && M[u][v] != INFINITY){
      if(color[v] != BLACK && M[u][v] != INF){
        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] == INFINITY ? -1 : d[i]) << endl;
    cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
  }
}

C++: #include<iostream>
#define LEN 100
#define INFTY 2000000001
#define NIL -1
#define WHITE 1
#define BLACK 0
using namespace std;
 
int main()
{
  int n,u,v,k,c,mincost=0;
  int G[LEN+1][LEN+1], d[LEN+1], pi[LEN+1], color[LEN+1];
 
  cin>>n;
 
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      G[i][j] = INFTY;
    }
  }
   
  for(int i = 0; i < n; i++){
    cin>>u>>k;
    for(int j = 0; j < k; j++){
      cin>>v>>c;
      G[u][v] = c;
    }
  }
 
  for(int i = 0; i < n; i++){
    d[i] = INFTY;
    pi[i] = NIL;
    color[i] = WHITE;
  }
   
  d[0] = 0;
   
  while(1){
    mincost = INFTY;
    for(int i = 0; i < n; i++){
      if(color[i] != BLACK && d[i] < mincost){
    mincost = d[i];
    u = i;
      }
    }

    if(mincost == INFTY) break;
    color[u] = BLACK;
    for(int i = 0; i < n; i++){
      if(d[i] > d[u] + G[u][i]){
        d[i] = d[u] + G[u][i];
        pi[i] = u;
      }
    }
  }
 
  for(int i = 0; i < n; i++){
    cout<<i<<" "<<d[i]<<endl;

  }
 
  return 0;
}

C++: #include <iostream>
#include <vector>
#define rep(i,N) for(int i = 0; i<(int)(N); i++)
#define REP(i,k,N) for(int i = k; i<(int)(N); i++)
#define MAX_C 100000
typedef long long ll;
using namespace std;

int main(){
        int n;
        cin >> n;
        vector< vector<int> > G(n, vector<int>(n,MAX_C+1));
        int u,k,v,c;
        rep(i,n){
                cin >> u >>k;
                rep(j,k){
                        cin >> v >> c;
                        G[u][v] = c;
                }
        }

        vector<ll> d(n, MAX_C * n);
        d[0]=0;
        bool update = true;
        while(update) {
                update  = false;
                rep(from,n) {
                        if(d[from] >= MAX_C * n) continue;

                        rep(to,n){
                                if(from == to || G[from][to] >= MAX_C + 1) continue;

                                if(d[to] > d[from] + G[from][to]) {
                                        update = true;
                                        d[to] = d[from] + G[from][to];
                                }

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

        return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra()
{
    int minv;
    int d[MAX]; // d[v]: Sからvに行ける最小コスト
    int color[MAX];

    rep(i, n)
    {
        d[i] = INF;
        color[i] = WHITE;
    }

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

    while (1) {
        minv = INF;
        int u = -1;
        rep(i, n)
        {
            if (d[i] < minv && color[i] != BLACK) {
                u = i;
                minv = d[i];
            }
        }
        if (u == -1) {
            break;
        }
        color[u] = BLACK;
        rep(v, n)
        {
            if (color[v] != BLACK && M[u][v] != INF) {
                if (d[u] + M[u][v] < d[v]) {
                    d[v] = d[u] + M[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }

    rep(i, n)
    {
        cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;

    rep(i, n)
    {
        rep(j, n)
        {
            M[i][j] = INF;
        }
    }

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

    dijkstra();

    return 0;
}