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 <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 minv;
    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){
        minv=INFTY;
        int u=-1;
        for (int i = 0; i < n; ++i) {
            if(minv>d[i] && color[i] != BLACK){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1) break;
        color[u]=BLACK;
        for (int v = 0; v < n; ++v) {
            if(color[v]!=BLACK && M[u][v] != INFTY){
                if(d[v]>d[u] + M[u][v]){
                    d[v] = d[u] + M[u][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 < k; ++j) {
            cin>>v>>c;
            M[u][v]=c;
        }
    }

    dijkstra();

    return 0;
}

C++: /*
 * Input
 * An edge-weighted graph G (V, E) and the source r.
 *
 * |V| |E| r
 * s0 t0 d0
 * s1 t1 d1
 * :
 * s|E|−1 t|E|−1 d|E|−1
 * |V| is the number of vertices and |E| is the number of edges in G. The graph
 * vertices are named with the numbers 0, 1,..., |V|−1 respectively. r is the
 * source of the graph.
 *
 * si and ti represent source and target vertices of i-th edge (directed) and di
 * represents the cost of the i-th edge.
 *
 * Output
 * c0
 * c1
 * :
 * c|V|−1
 * The output consists of |V| lines. Print the cost of the shortest path from
 * the source r to each vertex 0, 1, ... |V|−1 in order. If there is no path
 * from the source to a vertex, print INF.
 *
 * Constraints
 * 1 ≤ |V| ≤ 100000
 * 0 ≤ di ≤ 10000
 * 0 ≤ |E| ≤ 500000
 * There are no parallel edges
 * There are no self-loops
 */

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

int main() {
  int n, m, source = 0;
  cin >> n; // >> m >> source;
  vector<map<int, int>> adj(100000);

  vector<int> d(100000, 1000000001);
  bool visited[100000];
  int n_visited = 0;

  for (int u, k; cin >> u >> k;) {
    for (int i = 0, v, len; i < k; ++i) {
      cin >> v >> len;
      adj[u][v] = len;
    }
  }

  auto cmp = [&](int s, int t) { return d[s] > d[t]; };
  priority_queue<int, vector<int>, decltype(cmp)> q(cmp);

  d[source] = 0;
  q.push(source);
  while (!q.empty() and n_visited < n) {
    auto u = q.top();
    q.pop();
    if (visited[u])
      continue;
    ++n_visited;
    visited[u] = true;
    for (auto &kv : adj[u]) {
      d[kv.first] = min(d[kv.first], d[u] + kv.second);
      q.push(kv.first);
    }
  }

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

C++: #include<stdio.h>
#include<string.h>
long long arr[205][205];
long long min(long long a,long long b){
	return a>b?b:a;
}
int main() {
    int n,m;
    while(scanf("%d",&n)!=EOF){
    	long long x,y,c,d;
    	for(int i=0;i<205;i++){
    		for(int j=0;j<205;j++){
    		 arr[i][j]=10000000;	
			}
		}
    	for(int j=0;j<n;j++){
    	scanf("%lld %lld",&x,&y);
    	for(int h=0;h<y;h++){
    		scanf("%lld %lld",&c,&d);
    		arr[x][c]=min(arr[x][c],d);
		}
		}
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				arr[i][j]=min(arr[i][j],arr[i][k]+arr[k][j]);
			}
		}
	}
	printf("0 0\n");
	for(int i=1;i<n;i++){
    printf("%d %lld\n",i,arr[0][i]);
   }
    }
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <vector>
#include <utility>
using namespace std;
typedef pair<int, int> P;
struct edge {int to, cost;};
const int INF = (1 << 28);
int n;
vector<edge> G[110];


vector<int> dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, s));
    vector<int> d(n, INF);
    d[s] = 0;
    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (auto e: G[v]) {
            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;
}

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        int u, k, v, c;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v >> c;
            G[u].push_back(edge {v, c});
        }
    }
    vector<int> d = dijkstra(0);
    for (int i = 0; i < n; i++) {
        cout << i << " " << d[i] << endl;
    }

    return 0;
}