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 <bits/stdc++.h>
#include <cmath>

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef pair<double, double> P;

void print_line(vector<int> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

void warshall_floyd(int n, vector<vector<ll>> &d) {
    for (int k = 0; k < n; k++) {       // 経由する頂点
        for (int i = 0; i < n; i++) {    // 始点
            for (int j = 0; j < n; j++) {  // 終点
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

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

    vector<vector<ll>> distances(n, vector<ll>(n, INF));
    rep(i, n) distances[i][i] = 0;
    rep(i, n) {
        int j, k;
        cin >> j >> k;

        rep(l, k) {
            int u, c;
            cin >> u >> c;
            distances[j][u] = c;
        }
    }

    warshall_floyd(n, distances);

    rep(i, n) cout << i << ' ' << distances[0][i] << endl;

}

C++: #include<iostream>
#define N 101
#define INF 1<<21
using namespace std;

int A[N][N];
int n;
int visited[N];
int d[N];
int p[N];

void dijkstra(int b){
    d[b]=0;
    p[b]=-1;
    int node=-1;
    int minval=INF;
    while(1){
        node=-1;
        minval=INF;
        for(int i=0;i<n;i++){
            if(visited[i]==true) continue;
            if(d[i]<minval){
                node=i;
                minval=d[i];
            }
        }
        if(node==-1) break;
        visited[node]=true;
        for(int e=0;e<n;e++){
            if(A[node][e]==INF || visited[e]==true) continue;
            if(d[e]>d[node]+A[node][e]){
                d[e]=d[node]+A[node][e];
            }
        }
    }
}

void init(){
    int k;
    int b,e,val;
    cin>>n;
    for(int i=0;i<n;i++){
        visited[i]=false;
        d[i]=INF;
        p[i]=-1;
        for(int j=0;j<n;j++){
            A[i][j]=INF;
        }
    }
    for(int i=0;i<n;i++){
        cin>>b>>k;
        for(int j=0;j<k;j++){
            cin>>e>>val;
            A[b][e]=val;
        }
    }
}

int main(){
    init();

    dijkstra(0);

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

C++: #include <utility>
#include <vector>
#include <queue>
#include <functional>
#include <cassert>

using namespace std;

class Dijkstra {
#define MAX_V 101
  typedef pair<int, int> P;

private:
  const int INF = 1e9 + 10;
  struct Edge {
    int to, cost;
    Edge(int to, int cost): to(to), cost(cost) { }
  };

  int V;
  vector<Edge> G[MAX_V];

public:

  Dijkstra(int V): V(V) { 
    if (V >= MAX_V) {
      assert(false);
    }
  }

  void AddEdge(int from, int to, int cost) {
    G[from].push_back(Edge(to, cost));
  }

  vector<int> Solve(int s) {
    priority_queue<P, vector<P>, greater<P>> que;
    vector<int> d(V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
      P p = que.top(); que.pop();
      int v = p.second;
      if (d[v] < p.first) {
        continue;
      }
      for (int i = 0; i < G[v].size(); i++) {
        Edge e = G[v][i];
        if (d[e.to] > d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          que.push(P(d[e.to], e.to));
        }
      }
    }

    return d;
  }
};

#include <iostream>


int main() {
  int n;
  cin >> n;
  Dijkstra dijkstra(n);
  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int t, c;
      cin >> t >> c;
      dijkstra.AddEdge(u, t, c);
    }
  }

  vector<int> d = dijkstra.Solve(0);

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

  return 0;
}

C++: #include <iostream>
using namespace std;
#include <algorithm>
#define INF 1000000

int flg[100];

bool check(int p){

	if (flg[p] == 1) return false;
	return true;
}

int main(void){

	int n;

	cin >> n;
	int u, k;
	int date[100][100]; //date[??????????????????][?????´?????????]
	int dis[100]; //0????????????????????????????????¢

	memset(date, INF, sizeof(date));
	memset(dis, INF, sizeof(dis));
	memset(flg, 0, sizeof(flg));
	date[0][0] = 0;
	dis[0] = 0;
	for (int i = 0; i < n; i++){

		cin >> u >> k;
		for (int j = 0; j < k; j++){

			int v, c;
			cin >> v >> c;
			date[u][v] = c;
		}
	}

	while(1){
		int mini = INF;
		int p = -1;
		for (int i = 0; i < n; i++){
			if (check(i) && mini > dis[i]){
				p = i;
				mini = dis[i];
			}
		}
		if (p == -1) break;
		flg[p] = 1;
		for (int i = 0; i < n; i++){
			if (check(i) && dis[i] > dis[p] + date[p][i]){
				dis[i] = dis[p] + date[p][i];
			}
		}
	}

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