Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
type Node struct {
	cost int
	done bool
}

type Edge struct {
	to, cost int
}

const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	nodes := make([]Node, N)
	for i := 0; i < N; i++ {
		nodes[i].cost = INF
	}
	E := make([][]Edge, N)
	for i := 0; i < N; i++ {
		id, k := sc.nextInt(), sc.nextInt()
		for j := 0; j < k; j++ {
			to, cost := sc.nextInt(), sc.nextInt()
			E[id] = append(E[id], Edge{to, cost})
		}
	}
	nodes[0].cost = 0
	for {
		cur := 0
		minCost := INF
		for i := 0; i < N; i++ {
			n := nodes[i]
			if !n.done && n.cost < minCost {
				cur = i
				minCost = n.cost
			}
		}
		if minCost == INF {
			break
		}
		nodes[cur].done = true
		for i := 0; i < len(E[cur]); i++ {
			to, cost := E[cur][i].to, E[cur][i].cost+nodes[cur].cost
			if !nodes[to].done && cost < nodes[to].cost {
				nodes[to].cost = cost
			}
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprintln(wtr, i, nodes[i].cost)
	}
	wtr.Flush()
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    int n, u, k, v, c, l[101][101], ans[101];
    for (int i = 0; i < 101; i++) ans[i] = 1e9;
    ans[0] = 0;
    for (int i = 0; i < 101; i++) for (int j = 0;j < 101; j++)l[i][j] = 1e9;
    queue<int> q;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> u >> k;
        for(int j = 0;j < k; j++){
            cin >> v >> c;
            l[u][v] = c;
        }
    }
    q.push(0);
    while(!q.empty()){
        int _u = q.front();
        q.pop();
        for (int i = 0; i < n; i++){
            if (l[_u][i] != 1e9){
                if (ans[i] > ans[_u] + l[_u][i]){
                    ans[i] = ans[_u] + l[_u][i];
                    q.push(i);
                }
            }
        }
    }
    for (int i = 0 ; i < n; i++) cout << i << " "<< ans[i] << endl;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <stack>
#include <vector>
using namespace std;
const int maxx=110;
const int infinity=(1<<30);

int A[maxx][maxx],d[maxx];
bool flag[maxx];

int main (){
	int n,a,b,c;
	cin>>n;
	for(int i=0;i<maxx;i++){
		flag[i]=false;
		d[i]=infinity;
		for(int j=0;j<maxx;j++){
			A[i][j]=infinity;
		}
	}
	for(int i=0;i<n;i++){
		cin>>a>>b;
		for(int j=0;j<b;j++){
			cin>>c>>A[a][c];
		}
	}
	
	d[0]=0;
	while(1){
		int minv=infinity,mini=-1;
		for(int i=0;i<n;i++){
			if(flag[i]==false && d[i]<minv){
				minv=d[i];
				mini=i;
			}
		}
		if(mini==-1 || minv==infinity) break;
		flag[mini]=true;
		for(int i =0;i<n;i++){
			if(A[mini][i]!=infinity && flag[i]==false){
				if(d[mini]+A[mini][i]<d[i]){
					d[i]=d[mini]+A[mini][i];
				}
			}
		}
		
	}
	for(int i=0;i<n;i++) cout<<i<<" "<<d[i]<<endl;
	
	return 0;

}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int a,n,k,m[150][150];
  for(int i=0;i<150;i++)for(int j=0;j<150;j++)m[i][j]=100001;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a>>k;
    for(int j=0;j<k;j++){
      cin>>a;
      cin>>m[i][a];
    }
  }
  int dist[100]={};
  int visited[100]={};
  for(int i=1;i<100;i++)dist[i]=100001;
  while(1){
    int i=-1;
    for(int j=0;j<n;j++){
      if(visited[j]==0){
	if(i==-1||dist[i]>dist[j]){
	  i=j;
	}
      }
    }
    if(i==-1)break;
    visited[i]=1;
    for(int j=0;j<n;j++){
      int A=dist[i]+m[i][j];
      if(dist[j]>A){
	dist[j]=A;
      }
    }
  }
  for(int i=0;i<n;i++)printf("%d %d\n",i,dist[i]);
  return 0;
}

C++: #include <iostream>
#include <utility>
#include <vector>
using namespace std;

static const int MAX_N = 100;

void dijkstra(vector<vector<pair<int, int> > > way)
{
    int d[way.size()];
    bool on[way.size()];
    for (int i = 0; i < way.size(); i++) {
        d[i] = INT_MAX;
        on[i] = false;
    }
    d[0] = 0;
    while (1) {
//        cout << "d:";
//        for (int i = 0; i < way.size(); i++) {
//            cout << " " << d[i];
//        }
//        cout << endl;
        int u, minv = INT_MAX;
        for (int i = 0; i < way.size(); i++) {
            if (minv > d[i] && !on[i]) {
                minv = d[i];
                u = i;
            }
        }
        if (minv == INT_MAX) break;
        on[u] = true;
        for (auto itr = way.at(u).begin(); itr != way.at(u).end(); ++itr) {
            if (!on[itr->first]) {
                d[itr->first] = min(d[itr->first], d[u] + itr->second);
            }
        }
    }
    for (int i = 0; i < way.size(); i++) {
        cout << i << " " << d[i] << endl;
    }
}

int main()
{
    int n;
    cin >> n;
    vector<vector<pair<int, int> > > way(n);
    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;
            way.at(u).push_back(make_pair(v, c));
        }
    }
    dijkstra(way);
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;

struct Edge {
    ll t,w;
};

struct State {
    ll v;
    ll score;
    bool operator < (const State& tgt) const {
	return score > tgt.score;
    }
};

vector<ll> dijkstra(vector<vector<Edge>>& G, const int start) {
    const ll V = G.size();

    vector<ll>res(V,INT_MAX);
    priority_queue<State> q;
    q.push( State{0,0} );
    while( q.size() ) {
	State s = q.top(); q.pop();
	if( res[s.v] != INT_MAX ) continue;
	res[s.v] = s.score;
	for(auto& e : G[s.v]) {
	    if( res[e.t] != INT_MAX ) continue;
	    q.push( State{e.t, s.score + e.w} );
	}
    }
    return res;
}


int main () {

    ll V; cin >> V;
    vector<vector<Edge>> G(V);
    for(int i=0; i<V; i++) {
	ll u,k; cin >> u >> k;
	for(int j=0; j<k; j++) {
	    ll v,w; cin >> v >> w;
	    G[i].push_back( Edge{v,w} );
	}
    }
    vector<ll> res = dijkstra(G,0);
    for(auto& e : res) cout << e << endl;
    
    return 0;
}