Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)

	g := makeGraph(n)
	for i := 0; i < n; i++ {
		u := getNextInt(scanner)
		k := getNextInt(scanner)
		for ii := 0; ii < k; ii++ {
			v := getNextInt(scanner)
			c := getNextInt(scanner)
			g[u][v] = c
		}
	}

	ans := make([]int, n)
	im := make(IntMap, 1)
	im.increment(0)
	for len(im) < n {
		min := 1 << 30
		x := -1
		for u := range im {
			for v := 0; v < n; v++ {
				if im.get(v) != 0 {
					continue
				}
				if min > ans[u]+g[u][v] {
					min = ans[u] + g[u][v]
					x = v
				}
			}
		}
		im.increment(x)
		ans[x] = min
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", i, ans[i]))
	}
	writer.Flush()
}

func makeGraph(n int) [][]int {
	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		for ii := 0; ii < n; ii++ {
			g[i][ii] = 1 << 30
		}
	}

	return g
}

// IntMap ...
type IntMap map[int]int

func (m IntMap) get(key int) int {
	if _, ok := m[key]; ok {
		return m[key]
	}
	return 0
}
func (m IntMap) increment(key int) {
	if _, ok := m[key]; ok == false {
		m[key] = 0
	}
	m[key]++
}

C++: #include <bits/stdc++.h>
using namespace std;
static const int MAX=100;
static const int INFTY=1000000000;
static const int WHITE=-1;
static const int BLACK=1;

int A[MAX][MAX],dk[MAX],p[MAX];

void SSSP(int n){
    int C[n];
    for(int i=0;i<n;i++){
        C[i]=WHITE;
        dk[i]=INFTY;
    }
    dk[0]=0;
    while(true){
        int u=-1;int minv=INFTY;
        for(int i=0;i<n;i++){
            if(C[i]==WHITE&&minv>dk[i]){
                minv=dk[i];
                u=i;
            }
        }
        if(u==-1)break;
        C[u]=BLACK;
        for(int i=0;i<n;i++){
            if(C[i]==WHITE&&A[u][i]!=INFTY){
                if(dk[i]>dk[u]+A[u][i]){
                    dk[i]=dk[u]+A[u][i];
                }
            }
        }
    }
}

int main(){
    int n,v,k,u,d;
    cin>>n;
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)A[i][j]=INFTY;

    for(int i=0;i<n;i++){
        scanf("%d %d",&v,&k);
        for(int j=0;j<k;j++){
            scanf("%d %d",&u,&d);
            A[v][u]=d;
        }
    }
    SSSP(n);
    for(int i=0;i<n;i++){
        printf("%d %d\n",i,dk[i]);
    }

}

C++: #include <cstdio>
#include <map>
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;
map<int, int> *M;
int *d;

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

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

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

        if (u == -1) { break; }

        color[u] = BLACK;
        for (map<int, int>::iterator it = M[u].begin(); it != M[u].end(); it++) {
            if (color[it->first] != BLACK) {
                if (d[u] + it->second < d[it->first]) {
                    d[it->first] = d[u] + it->second;
                    color[it->first] = GRAY;
                }
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i, d[i]);
    }
}

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

    M = new map<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);
            M[u][v] = c;
        }
    }

    dijkstra();

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <cmath>
using namespace std;

#define INF 1e18
#define int long long
static const int MAX = 110;
static const int NOTFIXED = 0;
static const int FIXED = 1;

int n, m[MAX][MAX];

void dijkstra() {
    int d[n], status[n];
    for(int i = 0; i < n; i++) {
        d[i] = INF;
        status[i] = NOTFIXED;
    }
    d[0] = 0;
    status[0] = NOTFIXED;

    while(true) {
        int u = -1;
        int minv = INF;
        for(int i = 0; i < n; i++) {
            if(minv > d[i] && status[i] != FIXED) {
                u = i;
                minv = d[i];
            }
        }

        if(u == -1) break;
        status[u] = FIXED;
        for(int v = 0; v < n; v++) {
            if(m[u][v] != INF && status[v] != FIXED) {
                if(d[v] > d[u] + m[u][v]) {
                    d[v] = d[u] + m[u][v];
                    status[v] = NOTFIXED;
                }
            }
        }
    }

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

signed main() {
    cin >> n;

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

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

    dijkstra();

    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
const int INF = 1e9 ;
const int MAXN = 10100 ;
vector<pair<int, int> > edge[MAXN];
int n;
int d[MAXN], vis[MAXN];
priority_queue<pair<int, int> > q;
void Dij()
{
	for (int i = 0; i < n; ++i) d[i] = INF;
	d[0] = 0;
	q.push(make_pair(0, 0)) ;
	vis[0] = 1;
	while (! q.empty())
	{
		pair<int, int> cur = q.top();
		int u = cur.second;
		q.pop();
		vis[u] = 2;
		if (d[u] < cur.first * (-1)) continue ;
		for (int i = 0; i < edge[u].size(); ++i)
		{
			int to = edge[u][i].first;
			if (vis[to] == 2) continue ;
			if (d[to] > d[u] + edge[u][i].second)
			{
				d[to] = d[u] + edge[u][i].second;
				q.push(make_pair(d[to] * (-1), to));
				vis[to] = 1;
			}
		}
	}
}
int main()
{
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		int u, k;
		cin >> u >> k;
		for (int j = 1; j <= k; ++j)
		{
			int v, c;
			cin >> v >> c;
			edge[u].push_back(make_pair(v, c));
		}
	}
	Dij();
	for (int i = 0; i < n; ++i)
		cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
	return 0;
}

C++: #include<iostream>
#include<queue>
#define INF 100000000
using namespace std;
int main(){
  int n;cin>>n;
  int u,k,v,c;
  int mp[101][101],d[101];
  for(int i=0;i<=100;i++){
    d[i]=INF;
    for(int j=0;j<=100;j++)mp[i][j]=INF;
  }
    while(u!=n-1){
    cin>>u>>k;
    for(int i=0;i<k;i++){
      cin>>v>>c;
      if(mp[u][v]>c)mp[u][v]=c;
    }
  }
    d[0]=0;
    queue<int>p;
    p.push(0);
    int mn,s,cnt=n,t[101]={};
    t[0]=1;
    while(!p.empty()){
      s=p.back();
      mn=INF;
      for(int i=0;i<n;i++){
	if(t[i]==0){
	if(d[i]>d[s]+mp[s][i])d[i]=d[s]+mp[s][i];
	  if(mn>d[i])mn=d[i],k=i;
	}
      }
      if(mn!=INF)t[k]=1,p.push(k);
      else p.pop();
    }
    for(int i=0;i<n;i++)cout<<i<<" "<<d[i]<<endl;
    
  return 0;
}