Go: package main

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

const (
	white int = iota
	gray
	black
)

type node struct {
	id     int
	parent int
	edge   []int
	weight []int
	color  int
}

type graph struct {
	nodes    []node
	distance []int
}

var infty = 1 << 32
var null = -1

func constructgraph() *graph {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)

	g := &graph{make([]node, n), make([]int, n)}

	for i := 0; i < n; i++ {
		id := nextInt(sc)
		edges := nextInt(sc)
		n := node{}
		n.id = id
		n.edge = make([]int, edges)
		n.weight = make([]int, edges)
		n.color = white
		for j := 0; j < edges; j++ {
			to := nextInt(sc)
			w := nextInt(sc)
			n.edge[j] = to
			n.weight[j] = w
		}
		g.nodes[id] = n
	}
	return g
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func (g *graph) preparedijkstra(s int) {
	for i := 0; i < len(g.nodes); i++ {
		g.nodes[i].color = white
		g.nodes[i].parent = null
		g.distance[i] = infty
	}
	g.distance[s] = 0
}

func (g *graph) dijkstra(s int) []int {
	g.preparedijkstra(s)

	for {
		var u int
		mincost := infty
		for i, d := range g.distance {
			if g.nodes[i].color != black && mincost > d {
				mincost = d
				u = i
			}
		}

		if mincost == infty {
			break
		}

		g.nodes[u].color = black

		for i, e := range g.nodes[u].edge {
			if g.nodes[e].color != black {
				if g.distance[e] > g.distance[u]+g.nodes[u].weight[i] {
					g.distance[e] = g.distance[u] + g.nodes[u].weight[i]
					g.nodes[e].parent = u
					g.nodes[e].color = gray
				}
			}
		}
	}
	return g.distance
}

func printShortestPath(d []int) {
	for i, v := range d {
		fmt.Printf("%d %d\n", i, v)
	}
}

func main() {
	g := constructgraph()
	d := g.dijkstra(0)
	printShortestPath(d)
}

C++: #include<iostream>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<climits>
#include<queue>
using namespace std;
#define int long long
vector<double> dijk(vector<tuple<int,int,double>> edge_list, int start){
        const int DJMAX = INT_MAX;
        set<int> node_list;
        for(auto edge : edge_list){
                node_list.insert(get<0>(edge));
                node_list.insert(get<1>(edge));
        }
        int nodenum = *node_list.rbegin()+1;
        vector<vector<double>> cost_map(nodenum, vector<double>(nodenum, DJMAX));
        for(auto edge : edge_list){
                cost_map[get<0>(edge)][get<1>(edge)] = get<2>(edge);
        }
        vector<double> cost(nodenum,DJMAX);
        cost[start] = 0;
        vector<int> visited(nodenum,0);
        priority_queue<pair<int,int>> que;
        que.push(pair<double,int>(0,start));
        while(!que.empty()){
                int s = que.top().second;
                que.pop();
                visited[s] = 1;
                for(int j=0;j<nodenum;j++){
                        if(visited[j]==1) continue;
                        double nc = cost[s]+cost_map[s][j];
                        if(nc<cost[j]){
                                cost[j] = nc;
                                que.push(pair<double,int>(-cost[j],j));
                        }
                }
        }
        return cost;
}
signed main(){
        int n;
        cin >> n;
        vector<tuple<int, int, double>> edges;
        for(int i=0;i<n;i++){
                int vs, vn;
                cin >> vs >> vn;
                for(int j=0;j<vn;j++){
                        int vt,c;
                        cin >> vt >> c;
                        edges.push_back(tuple<int,int,double>(vs,vt,c));
                }
        }
        auto ans = dijk(edges, 0);
        for(int i=0;i<n;i++){
                cout << i << " " << ans[i] << endl;
        }
        return 0;
}

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