Go: package main

import (
	"strconv"
	"fmt"
	"bufio"
	"os"
)
const INF = 1 << 21
var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}


func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	adj := make([][]int, n)
	for i := range adj {
		adj[i] = make([]int, n)
	}

	for i := 0;i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			v := nextInt()
			c := nextInt()
			adj[u][v] = c
		}
	}

	// for i := range adj {
	// 	fmt.Println(adj[i])
	// }

	dist := make([]int, n)
	prev := make([]int, n)
	visited := make([]bool, n)
	dijkstra := func(start int, size int) {
		for i := 0; i < size; i++ {
			dist[i] = INF
			prev[i] = -1
			visited[i] = false
		}
		dist[start] = 0
		for {
			u := -1
			tmp_min := INF
			for i := 0; i < size; i++ {
				if visited[i] == false && dist[i] < tmp_min {
					tmp_min = dist[i]
					u = i
				}
			}
			if u == -1 {
				break
			}
			visited[u] = true
			for i := 0; i < size; i++ {
				if adj[u][i] > 0 {
					w := adj[u][i]
					newlen := dist[u] + w
					if newlen < dist[i] {
						dist[i] = newlen
						prev[i] = u
					}
				}
			}
		}
	}
	dijkstra(0, n)
	for i, cost := range dist {
		fmt.Printf("%d %d\n", i, cost)
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_12_B&lang=jp

struct edge
{
    int to;
    int cost;
};
vector<edge> G[10005];
int dst[105];

void dij() {
    min_priority_queue<P> q;
    q.push({0, 0});
    dst[0] = 0;

    while(!q.empty()) {
        P f = q.top(); q.pop();
        int v = f.first;
        if (dst[v] < f.second) continue;

        for (edge e : G[v]) {
            if (dst[e.to] > dst[v] + e.cost) {
                dst[e.to] = dst[v] + e.cost;
                q.push({e.to, dst[e.to]});
            }
        }
    }
}

int main() {
    int n; cin >> n;
    REP(i, n) {
        dst[i] = INF;

        int u, k; cin >> u >> k;
        REP(i, k) {
            int v, c; cin >> v >> c;
            G[u].push_back({v, c});
        }
    }

    dij();

    REP(i, n) {
        printf("%d %d\n", i, dst[i]);
    }

    return 0;
}

C++: #include<map>
#include<list>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LOOP1(n) for(int i=0;i<n;i++)
#define LOOP2(n) for(int j=0;j<n;j++)
#define LOOP3(n) for(int k=0;k<n;k++)
#define Psi pair<string,int>
#define Pis pair<int,string>
#define Pii pair<int,int>
// ??????????????????memset(a,0,sizeof(a));
// ?´???°?????? if(x<2)return0;else if(x==2)return1;if(x%2==0)return0;for(i=3;i*i<=x;i+=2){if(x%i==0)return0;}return1;}p440
//vector size();push_back(x);pop_back();begin();end();insert(p,x);erase(p);clear();
//stack  size();top();pop();push(x);emtpy();
//queue  size();front();pop();push(x);empty();
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 1;
static const int GRAY = 2;
static const int BLACK = 3;
int n; int M[MAX][MAX];
int color[MAX]; int d[MAX]; int p[MAX];
int main(){
	int u, k, v, c, uu, sum = 0;
	cin >> n;
	LOOP1(n){
		LOOP2(n){
			M[i][j] = INFTY;
		}
	}
	LOOP1(n){
		cin >> u >> k;
		LOOP2(k){
			cin >> v >> c;
			M[u][v] = c;
		}
	}
	for (int i = 0; i < n; i++){
		color[i] = WHITE;
		d[i] = INFTY;
		p[i] = -1;
	}
	d[0] = 0;
	while (true){
		int mincost = INFTY;
		LOOP1(n){
			if (color[i] != BLACK && mincost > d[i]){
				mincost = d[i];
				uu = i;
			}
		}
		if (mincost == INFTY) break;
		color[uu] = BLACK;
		LOOP1(n){
			if (M[uu][i] != INFTY && color[i] != BLACK){
				if (M[uu][i] + d[uu] < d[i]){
					d[i] = d[uu] + M[uu][i];
					color[i] = GRAY;
					p[i] = u;
				}
			}
		}
	}
	LOOP1(n){
		cout << i << ' ' << d[i] << endl;
	}
	return 0;
}

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++: #include<iostream>
using namespace std;
#define MAX 100
#define White 1
#define Black 2
#define Red 3
#define Infinit 1e+8
struct Vertex {
	int weight,color, parent,totalweight;
};
int M[MAX][MAX];
int n;
Vertex v[MAX];
void search() {
	int pointer, min;
	for (int i = 0; i < n; i++) {
		if (i == 0) {
			v[i].weight = 0;
		}
		else {
			v[i].weight = Infinit;
		}
		v[i].color = White;
		v[i].parent = -1;
	}
	while (true) {
		min = Infinit;
		pointer = -1;
		for (int i = 0; i < n; i++) {
			if (v[i].color != Black && min > v[i].weight) {
				min = v[i].weight;
				pointer = i;
			}
		}
		if (min == Infinit) break;
		v[pointer].color = Black;
		for (int k = 0; k < n; k++) {
			if (M[pointer][k] != -1 && v[k].color != Black) {
				if (v[pointer].weight+M[pointer][k]<v[k].weight) {
					v[k].weight = v[pointer].weight+M[pointer][k];
					v[k].parent = pointer;
					v[k].color = Red;
				}
			}
		}

	}
	for (int i = 0; i < n; i++) {
		cout << i << " " << v[i].weight << endl;
	}
	
}
int main() {
	int u,k,v,c;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			M[i][j] = -1;
		}
	}
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int i = 0; i < k; i++) {
			cin >> v >> c;
			M[u][v] = c;
		}
	}
	search();
}