Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const BIG_COST = 200000

const (
	ST_NOT_YET = iota
	ST_JOINED
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nNodes := scanInt(sc)

	costs := make([][]int, nNodes)
	graph := make([][]int, nNodes)

	states := make([]int, nNodes)
	costSums := make([]int, nNodes)

	for i := 0; i < nNodes; i++ {
		costs[i] = make([]int, nNodes)
		costSums[i] = BIG_COST
	}

	for i := 0; i < nNodes; i++ {
		u := scanInt(sc)
		k := scanInt(sc)
		graph[u] = make([]int, k)
		for d := 0; d < k; d++ {
			v := scanInt(sc)
			graph[u][d] = v
			costs[u][v] = scanInt(sc)
		}
	}

	costSums[0] = 0
	for {
		minCost := BIG_COST
		var u int

		for i, cost := range costSums {
			if states[i] != ST_JOINED && cost < minCost {
				minCost = cost
				u = i
			}
		}

		if minCost == BIG_COST {
			break
		}

		states[u] = ST_JOINED

		for _, v := range graph[u] {
			cost := minCost + costs[u][v]
			if cost < costSums[v] {
				costSums[v] = cost
			}
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i, cost := range costSums {
		fmt.Fprintf(w, "%d %d\n", i, cost)
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

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 min;
   int d[MAX], color[MAX];

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

   d[0] = 0;
   color[0] = GRAY;
   
   while ( 1 ) {
      min = INFTY; 
      int a = -1;
      for ( int i = 0; i < n; i++ ) {
         if ( min > d[i] && color[i] != BLACK ) {
             a = i;
             min = d[i];
         }
      }

      if ( a == -1 ) break;
      color[a] = BLACK;
      
      for ( int v = 0; v < n; v++ ) {
         if ( color[v] != BLACK && M[a][v] != INFTY ) {
            if ( d[v] > d[a] + M[a][v] ) {
               d[v] = d[a] + M[a][v];
               color[v] = GRAY;
            }
         }
      }
   }

   for ( int i = 0; i< n; i++ ) {
      cout << i << " " << ( d[i] == INFTY ? -1 : d[i] ) << endl;
   }
}

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

   int k, c, u, v;
  
   for ( int i = 0; i < n; i++ ) {
      cin >> u >> k;  

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

   dijkstra();

   return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <climits>
#include <cstring>

using namespace std;

#define SWAP(type, a, b) do { type t = a; a = b; b = t; } while(0)

typedef struct {
    int* verIdx;
    int num;
} Heap;

int* d; 
int* weight;
int n;

void makeMinHeap(Heap *heap, int idx);
void insert(Heap *heap, int key);
int extract(Heap *heap);

static inline int getParent(int idx) { return idx / 2; }
static inline int getLeft(int idx) { return idx * 2; }
static inline int getRight(int idx) { return idx * 2 + 1; }
static inline bool isCorrectHeapIdx(int idx, int heapSize) { return idx <= heapSize && 1 <= idx; }
static inline bool isEmpty(Heap *heap) { return heap->num <= 0; }

static inline int getMinCost(int idx) {
    return d[idx];
}

void makeMinHeap(Heap *heap, int idx) {
    int left = getLeft(idx);
    int right = getRight(idx);

    int minIdx = idx;
    if(isCorrectHeapIdx(left, heap->num) && getMinCost(heap->verIdx[minIdx]) > getMinCost(heap->verIdx[left])) {
        minIdx = left;
    } if(isCorrectHeapIdx(right, heap->num) && getMinCost(heap->verIdx[minIdx]) > getMinCost(heap->verIdx[right])) {
        minIdx = right;
    }

    if(minIdx != idx) {
        SWAP(int, heap->verIdx[minIdx], heap->verIdx[idx]);
        makeMinHeap(heap, minIdx);
    }
}

void insert(Heap *heap, int* key) {
    heap->verIdx[++heap->num] = *key;
    for(int i = getParent(heap->num); i >= 1; i = getParent(i)) {
        makeMinHeap(heap, i);
    }
}

void extract(Heap *heap, int* key) {
    *key = heap->verIdx[1];
    heap->verIdx[1] = heap->verIdx[heap->num--];
    makeMinHeap(heap, 1);
}

static inline bool isConnected(int s, int t) {
    return weight[s * n + t] != INT_MAX;
}

static inline int getWeight(int s, int t) {
    return weight[s * n + t];
}

void solve(int s) {
    Heap que;
    bool* isAddS = new bool[n]();

    que.verIdx = new int[n * n];
    que.num = 0;

    d = new int[n];
    d[s] = 0;
    for(int i = 0; i < n; i++) {
        if(s != i) {
            d[i] = INT_MAX;
        }
    }
    
    insert(&que, &s);

    while(1) {
        int u;
        while(1) {
            if(isEmpty(&que)) {
                return;
            } 

            extract(&que, &u);
            if(!isAddS[u]) {
                break;
            }
        }

        isAddS[u] = true;

        for(int i = 0; i < n; i++) {
            if(isConnected(u, i) && !isAddS[i]) {
                if(d[u] + getWeight(u, i) < d[i]) {
                    d[i] = d[u] + getWeight(u, i);
                }
                insert(&que, &i);
            }
        }
    }

    return;
}

int main() {

    scanf("%d", &n);

    weight = new int[n * n];

    for(int i = 0; i < n * n; i++) {
        weight[i] = INT_MAX;
    }
    

    for(int i = 0; i < n; i++) {
        int s;
        int deg;

        scanf("%d %d", &s, &deg);
        for(int j = 0; j < deg; j++) {
            int t;
            int w;

            scanf("%d %d", &t, &w);

            weight[s * n + t] = w;
        }
    }

    solve(0);

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