Go: package main

import (
	"fmt"
	"container/heap"
)

type Node struct {
	Id int
	Dis int
}

type PriorityQueue []*Node

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dis < pq[j].Dis
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(*Node))
}

func (pq *PriorityQueue) Pop() interface{} {
	n := len(*pq)
	pop := (*pq)[n-1]
	*pq = (*pq)[0:n-1]
	return pop
}

func main() {
	var n int
	fmt.Scan(&n)

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
			fmt.Scan(&c[u][j])
		}

		if u == 0 {
			d[u] = 0
		} else {
			d[u] = 1 << 30
		}
		pq.Push(&Node{u, d[u]})
	}
	heap.Init(&pq)

	for pq.Len() > 0 {
		node := heap.Pop(&pq).(*Node)
		for i := 0; i < len(g[node.Id]); i++ {
			nextId := g[node.Id][i]
			nextDis := node.Dis + c[node.Id][i]
			if nextDis < d[nextId] {
				d[nextId] = nextDis
				heap.Push(&pq, &Node{nextId, nextDis})
			}
		}
	}

	for i := 0; i < n; i++ {
		fmt.Println(i, d[i])
	}
}

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

const int INF = INT_MAX;
typedef pair<int, int> P;

struct edge {int to, cost;};

int dijkstra(const vector<vector<edge>> &graph, int s, int g ) {
  vector<int> d(graph.size(), INF);
  d[s] = 0;
  priority_queue<P, vector<P>, greater<P>> now;
  now.push(P(0, s));
  
  while(!now.empty()) {
    int pos = now.top().second; now.pop();
    if (pos == g) {
      for(int i = 0; i <= g; i++) {
        cout << i << " " << d[i];
        if(i != g) cout << endl;
      }
      return INF;
    }
    for(auto ed: graph[pos]) {
      if(d[ed.to] > d[pos] + ed.cost) {
        d[ed.to] = d[pos] + ed.cost;
        now.push(P(d[ed.to], ed.to));
      }
    }
  }
  return INF;
}
  
int main() {
  int num;
  cin >> num;
  vector<vector<edge>> graph(num, vector<edge>());
  int f, n, k, v, c;
  for(int i = 0; i < num; i++) {
    cin >> f >> k;
    for(int j = 0; j < k; j++) {
      cin >> v >> c;
      graph[f].push_back(edge{v, c});
      // graph[v].push_back(edge{f, c});
    }
  }
  dijkstra(graph, 0, num - 1);
  return 0;
}

C++: #include <iostream>
#include <queue>
#include <limits>
using namespace std;

struct vec {
    int t, c;
    vec(int to, int cost):t(to),c(cost){}
    bool operator>(const vec &r)const{return t>r.t;}
};
vector<vec> adj[100];
int d[100];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++) d[i]=numeric_limits<int>::max();
    for(int i=0; i<n; i++) {
        int u,k;
        cin>>u>>k;
        adj[u].reserve(k);
        for(int j=0; j<k; j++) {
            int v,c;
            cin>>v>>c;
            adj[u].push_back(vec(v,c));
        }
    }
    priority_queue<vec, vector<vec>, greater<vec> >q;
    q.push(vec(0,0));
    while(!q.empty()) {
        vec e=q.top();
        q.pop();
        if(d[e.t]<=e.c) continue;
        d[e.t]=e.c;
        for(vector<vec>::iterator it=adj[e.t].begin(); it!=adj[e.t].end(); ++it) q.push(vec(it->t, e.c+it->c));
    }
    for(int i=0; i<n; i++) cout<<i<<' '<<d[i]<<'\n';
    return 0;
}

C++: //
// Created by tattsun on 2017/02/16.
//

#include <iostream>

#define MAX_N 101
#define NIL -1
#define INFTY 1000000

using namespace std;

enum Status {
    NotVisited,
    Visited,
};

int n;
int w[MAX_N][MAX_N];
Status st[MAX_N];

int min(int x, int y) {
    if(x < y) return x;
    return y;
}

int dfs(int v, int cost, int target) {
    if(v == target) {
        return cost;
    }

    int c = MAX_N * INFTY;

    st[v] = Visited;

    for(int i=0; i<n; i++) {
        int x = w[v][i];
        if(x == INFTY || st[i] == Visited) continue;

        c = min(c, dfs(i, cost+x, target));
    }

    st[v] = NotVisited;

    return c;
}

int solve(int i) {
    return dfs(0, 0, i);
}

int main() {
    for(int i=0; i<MAX_N; i++) {
        st[i] = NotVisited;
        for (int j = 0; j < MAX_N; j++) {
            w[i][j] = INFTY;
        }
    }

    cin >> n;

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

    for(int i=0; i<n; i++) {
        cout << i << " " << solve(i) << endl;
    }
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1 << 30;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

vector<pii> G[N];
int d[N];

int main() {
	int n; cin >> n;
	rep(i, n) {
		int _, n2; cin >> _ >> n2;
		rep(j, n2) {
			int v, c; cin >> v >> c;
			G[i].push_back(pii(c, v));
		}
	}
	rep(i, n) d[i] = INF;

	priority_queue<pii, vector<pii>, greater<pii>> Q;
	d[0] = 0;
	Q.push(pii(0, 0));
	while (!Q.empty()) {
		pii p = Q.top(); Q.pop();
		for (auto i : G[p.second]) {
			if (d[i.second] <= d[p.second] + i.first) continue;
			d[i.second] = d[p.second] + i.first;
			Q.push(i);
		}
	}
	rep(i, n) cout << i << ' ' << d[i] << endl;
}

C++: #include<iostream>
using namespace std;
static const int MAX=100;
static const int INF=(1<<21);
static const int APE=0;
static const int MID=1;
static const int BOT=2;

int n, M[MAX][MAX];

void dijkstra(){
  int mv, i, u, v;
  int d[MAX], c[MAX];

  for(i=0;i<n;i++){
    d[i]=INF;
    c[i]=APE;
  }

  d[0]=0;
  c[0]=MID;
  while(1){
    mv=INF;
    u=-1;
    for(i=0;i<n;i++){
      if(mv>d[i]&&c[i]!=BOT){
        u=i;
        mv=d[i];
      }
    }
    if(u==-1)break;
    c[u]=BOT;
    for(v=0;v<n;v++){
      if(c[v]!=BOT&&M[u][v]!=INF){
        if(d[v]>d[u]+M[u][v]){
          d[v]=d[u]+M[u][v];
          c[v]=MID;
        }
      }
    }
  }
  for(i=0;i<n;i++){
    cout<<i<<" "<<(d[i]==INF ? -1 : d[i])<<endl;
  }
}

int main(){
  int i, j, k, c, u, v;

  cin>>n;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=INF;
    }
  }

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

  return 0;
}