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 <iostream>
#include <vector>
#include <queue>
using namespace std;
	
const long long INF = 7+(1e+18);
typedef long long Weight;
struct Edge {  //src:辺の始点,dst:辺の終点,weight:辺の重さ
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : //辺は重さが重いものを"小さい"と定義する
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

//引数 g:隣接リスト,s:始点,dist:各頂点までの距離が入る,prev:最短路木の親頂点が入る
//戻値 なし
void shortestPath(const Graph &g,int s,vector<Weight> &dist,vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q;
  Q.push(Edge(-2, s, 0));
  while(!Q.empty()) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    for(auto f=g[e.dst].begin();f!=g[e.dst].end();f++){
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}
//-----------------
int main()
{ 
    while(true){
        int i, j, k, V;
        int u, v;
        Weight c;
        if(!(cin >> V))break;
        Graph g(V);    //頂点数vの空隣接リストgを生成
        for(i=0; i<V; i++){
            cin >> u >> k;
            for(j=0; j<k; j++){
                cin >> v >> c;
                g[u].push_back(Edge(u, v, c));    //隣接リストgにsからtに向かう重さwの辺を追加
            }
        }
        vector<Weight> dist;
        vector<int> prev;
        shortestPath(g,0,dist,prev);
        for(i=0; i<V; i++){
            cout << i << " " << dist[i] << endl;
        }
    }
  
    return 0;
}

C++: #include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#define INF 100000000
#define ll long long
using namespace std;
int main(){
  int n;
  cin >> n;
  vector< vector< pair<int,int> > > edges(n);
  for(int i = 0; i < n; i++){
    int id = 0;
    cin >> id;
    int k;
    cin >> k;
    for(int j = 0; j < k; j++){
      int v, c;
      cin >> v >> c;
      edges[id].push_back(make_pair(v,c));
    }
  }

  priority_queue< pair<int,int>, vector< pair<int,int> > , less< pair<int,int> > > pq;
  pq.push(make_pair(0,0));
  vector<long long> dist(n, INF);
  dist[0] = 0;
  while(!pq.empty()){
    ll source = pq.top().second;
    pq.pop();
    for(pair<int,int> edge: edges[source]){
      if(dist[edge.first] > dist[source] + edge.second){
	dist[edge.first] = dist[source] + edge.second;
	pq.push(make_pair(dist[edge.first], edge.first));
      }
    }
  }
  for(int i = 0; i < n; i++){
    cout << i << ' ';
    cout << dist[i] << endl;
  }
}

C++: #include <map>
#include <vector>
#include <cstdio>
using namespace std;
int main(){
	int n=0,N,i,j,k,c;
	scanf("%d",&N);
	vector<map<int,int> >dist(N);
	vector<bool>used(N);
	vector<int>cost(N);
	for(;n<N;n++){
		cost[n]=9999999;
		for(scanf("%d%d",&i,&k);k--;dist[j][i]=c)scanf("%d%d",&j,&c); //i->j cost c
	}
	for(cost[0]=0;;){ //dijkstra
		int m=9999999;
		for(i=0;i<N;i++)if(!used[i]&&m>cost[i])m=cost[i];
		if(m==9999999)break;
		for(j=0;j<n;j++)if(m==cost[j]){
			map<int,int>::iterator it=dist[j].begin();
			for(used[j]=1;it!=dist[j].end();it++)if(cost[it->first]>it->second+cost[j])cost[it->first]=it->second+cost[j];
		}
	}
	for(i=0;i<n;i++)printf("%d %d\n",i,cost[i]);
}

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;
}