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 <bits/stdc++.h>
using namespace std;
#define MAX 101
#define INF 100100

static const int WHITE = 0; //not visited
static const int GRAY = 1; //visited
static const int BLACK = 2;

int n, M[MAX][MAX];
int color[MAX];
int dist_from_start[MAX];
int parent_node[MAX];

void dijkstra(int start) {
  //initialize
  for (int i = 1; i <= n; i++) {
    color[i] = WHITE;
    dist_from_start[i] = INF;
    parent_node[i] = -1;
  }

  dist_from_start[start] = 0;
  color[start] = GRAY;

  while (true) {
    int mincost = INF;
    int now = -1;

    //初回はmincost = 0になる(始点)
    for (int i = 1; i <= n; i++) {
      if (color[i] != BLACK && dist_from_start[i] < mincost) {
        mincost = dist_from_start[i];
        now = i;
      }
    }

    if (now == -1) break;

    color[now] = BLACK;

    for (int v = 1; v <= n; v++) {
      if (color[v] != BLACK && M[now][v] != INF) {
        if (dist_from_start[now] + M[now][v] < dist_from_start[v]) {
          dist_from_start[v] = dist_from_start[now] + M[now][v];
          parent_node[v] = now;
          color[v] = GRAY;
        }
      }
    }
  }

  for (int i = 1; i <= n; i++) cout << i-1 << " " << (dist_from_start[i] == INF ? -1 : dist_from_start[i]) << endl;
}

int main() {
  cin >> n;

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

  int u, k;
  for (int i = 1; i <= n; i++) {
    cin >> u >> k;
    for (int j = 1; j <= k; j++) {
      int v, t;
      cin >> v >> t;
      M[u+1][v+1] = t;
    }
  }

  dijkstra(1);

  return 0;
}

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

vector<vector<pair<int, int>>> v;
vector<int> d, color;

const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

void dijkstra(){
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
  q.push(make_pair(0, 0));
  d[0] = 0;

  while(!q.empty()){
    auto next = q.top(); q.pop();
    if(color[next.second] == BLACK) continue;

    color[next.second] = BLACK;

    for(auto ve : v[next.second]){
      if(color[ve.first] != BLACK && d[ve.first] > d[next.second] + ve.second){
        d[ve.first] = d[next.second] + ve.second;
        color[ve.first] = GRAY;
        q.push(make_pair(d[ve.first], ve.first));
      }
    }
  }
}

int main(){
  int n; cin >> n;

  v.resize(n);
  d.resize(n);
  color.resize(n);

  for(int i=0; i<n; ++i){
    d[i] = numeric_limits<int>::max();

    int u, k, ve, c; cin >> u >> k;
    for(int l=0; l<k; ++l){
      cin >> ve >> c;
      v[u].push_back(make_pair(ve, c));
    }
  }

  dijkstra();

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

C++: #include <cstdio>
#include <queue>
#include <utility>
using namespace std;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int>> adj[100];
int *d;

void dijkstra() {
    priority_queue<pair<int, int>> PQ;
    int d[n], color[n];

    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[n] = WHITE;
    }
    d[0] = 0;
    PQ.push(make_pair(0, 0));

    while (!PQ.empty()) {
        pair<int, int> f = PQ.top();
        PQ.pop();

        int u = f.second;
        color[u] = BLACK;

        if (d[u] < f.first * (-1)) { continue; }

        for (int j = 0; j < adj[u].size(); j++) {
            int v = adj[u][j].first;
            if (color[v] == BLACK) { continue; }
            if (d[u] + adj[u][j].second < d[v]) {
                d[v] = d[u] + adj[u][j].second;
                // printf("d[%d] = %d\n", v, d[v]);
                PQ.push(make_pair(d[v] * (-1), v));
                color[v] = GRAY;
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i, d[i]);
    }
}

int main() {
    scanf("%d", &n);

    // adj = new vector<pair<int, int>>[n];

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

    dijkstra();

    return 0;
}

C++: #include <iostream>
using namespace std;
int n;
static const int MAX = 100;
static const int INF = (1 << 21);
int M[MAX][MAX];
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;


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

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

    d[0] = 0;
    // color[]

    while(1){
        minv = INF;
        int u = -1;

        for (int i = 0; i < n; i++){
            if (minv > d[i] && color[i] != BLACK){
                minv= d[i];
                u = i;
            }
        }

        if (u == -1){ //全部探索済み
            break;
        }

        color[u] = BLACK;
        for (int i = 0; i < n; i++){
            if (color[i] != BLACK && d[i] > M[u][i] != INF){
                if (d[i] > d[u] + M[u][i]){
                    color[i] = GRAY;
                    d[i] = d[u] + M[u][i];
                }
            }
        }
    }
    for (int i = 0; i < n; i++){
            cout << i << " ";
            if (d[i] == INF){
                cout << -1 << endl;
            }else{
                cout << d[i] << endl;
            }
            
        }
}

int main(void){
    int tmp;

    cin >> n;

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

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

    return 0;
}