Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

const NIL = -1

type Node struct {
	id     int
	weight int
}

func init() {
	sc.Split(bufio.ScanWords)
}

type NodeHeap []Node

func (h NodeHeap) Len() int           { return len(h) }
func (h NodeHeap) Less(i, j int) bool { return h[i].weight < h[j].weight }
func (h NodeHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *NodeHeap) Push(x interface{}) {
	*h = append(*h, x.(Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()

	list := make([][]int, n)
	weight := make([]int, n)
	for i := range list {
		list[i] = make([]int, n)
		weight[i] = NIL
		for j := range list[i] {
			list[i][j] = NIL
		}
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		for j := 0; j < k; j++ {
			v := scanInt()
			w := scanInt()
			list[u][v] = w
		}
	}

	start := Node{id: 0, weight: 0}
	h := &NodeHeap{start}
	heap.Init(h)

	for h.Len() > 0 {
		node := heap.Pop(h).(Node)
		if weight[node.id] != NIL {
			continue
		}
		weight[node.id] = node.weight

		for i, w := range list[node.id] {
			if w == NIL {
				continue
			}
			heap.Push(h, Node{id: i, weight: w + node.weight})
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		fmt.Fprint(w, i)
		fmt.Fprint(w, " ")
		fmt.Fprint(w, weight[i])
		fmt.Fprintln(w)
	}
	w.Flush()
}

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

#define N 120
int n;

int g[N][N];

int weight[N];
bool us[N];

int prim(){

  int v;
  int ans=0;
  weight[0]=0;
  
  while(true){
    v=-1;
   
    for(int i=0;i<n;i++){
      if(us[i]!=true && (v==-1 ||weight[i]<weight[v]))v=i;
    }

    if(v==-1)break;
    us[v]=true;
    ans+=weight[v];

    for(int i=0;i<n;i++){
      if(weight[i]>(g[v][i]+weight[v])){

        weight[i]=(g[v][i]+weight[v]);
        //      cout <<"fsafa"<<endl;
      }
    }
  }
  return ans;
}


int main(){

  int u,k1,c,v;

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      g[i][j]=53535;
    }
  }

//load n
  cin >>n;

  //load data
  for(int i=0;i<n;i++){
    weight[i]=INT_MAX;
    us[i]=false;
    scanf("%d %d",&u,&k1);
    for(int j=0;j<k1;j++){
      scanf("%d %d",&v,&c);
      g[u][v]=c;
      //    cout <<g[i][j]<<" ";
    }
    //    cout <<endl;
  }




  //print
  prim();

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

}

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