Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

const NIL = -1

type Node struct {
	id     int
	weight int
}

func init() {
	sc.Split(bufio.ScanWords)
}

type NodeHeap []Node

func (h NodeHeap) Len() int           { return len(h) }
func (h NodeHeap) Less(i, j int) bool { return h[i].weight < h[j].weight }
func (h NodeHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *NodeHeap) Push(x interface{}) {
	*h = append(*h, x.(Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()

	route := make([][]Node, n)
	weight := make([]int, n)
	for i := 0; i < n; i++ {
		weight[i] = NIL
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		route[i] = make([]Node, k)
		for j := 0; j < k; j++ {
			route[u][j] = Node{id: scanInt(), weight: scanInt()}
		}
	}

	start := Node{id: 0, weight: 0}
	h := &NodeHeap{start}
	heap.Init(h)

	for h.Len() > 0 {
		node := heap.Pop(h).(Node)
		if weight[node.id] != NIL {
			continue
		}
		weight[node.id] = node.weight

		for _, nextNode := range route[node.id] {
			if weight[nextNode.id] != NIL {
				continue
			}
			nextNode.weight += node.weight
			heap.Push(h, nextNode)
		}
	}

	for i, w := range weight {
		fmt.Println(i, w)
	}
}

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

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
const int MAX_N =10000;

struct edge
{
	int to,cost;
	edge(int _to,int _cost){
		to =_to;
		cost =_cost;
	}
};

int V;
vector<edge> cost[MAX_N];
int d[MAX_N];
bool visit[MAX_N];
void dijkstra(int s){
	d[s]=0;
	priority_queue<pii, vector<pii> ,greater<pii> > que;
	que.push(mp(0,s));
	while(!que.empty()){
		pii p =que.top();
		que.pop();
		int v =p.second;
		//if(d[v] != p.first)continue;
		for(int i =0;i <cost[v].size();i++){
			edge e =cost[v][i];
			if(d[e.to] >d[v]+e.cost){
				d[e.to] =d[v] +e.cost;
				que.push(mp(d[e.to],e.to));
			}
		}
	}
}

int main(){
	cin>>V;
	for(int i =0;i <V;i++){
		d[i]=INF;
		int u,k;
		cin>>u>>k;
		for(int j =0;j <k;j++){
			int to,c;
			cin>>to>>c;
			cost[u].push_back(edge(to,c));
		}
	}
	
	dijkstra(0);
	for(int i =0;i <V;i++){
		cout <<i<<" "<<d[i]<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
typedef unsigned short ushort;
typedef vector <int> vi;
typedef vector <vi> vvi;

class blanch{
	public:
		bool visited;
		int distance;
		ushort from;
};
typedef vector <blanch> vb;

int make_graph(vvi &graph, vb &nodes){
	int n=graph.size();
	for (int i=0; i<n; i++){
		for (int j=0; j<n; j++){
			graph[i][j]=-1;
		}
		nodes[i].visited = false;
		nodes[i].distance = INT_MAX;
	}

	for (int i=0; i<n; i++){
		int i2,n2;
		cin>>i2;
		cin>>n2;
		for (int j=0; j<n2; j++){
			int j2;
			cin>>j2;
			cin>>graph[i2][j2];
		}
	}
	return 0;
}

int Shortest_Path(vvi &graph, vb &nodes){

	int n = graph.size(), p1=0;
	nodes[p1].distance = 0;

	while (p1 != -1){
		nodes[p1].visited=true;
		cout<<"node: "<<p1<<", distance: "<<nodes[p1].distance<<endl;
		for (int p2 = 0; p2 < n; p2++){
			int *tmp = &graph[p1][p2];
			if (*tmp!=-1 && nodes[p2].visited==false){
				int tmp2 = *tmp + nodes[p1].distance;
				if (tmp2 < nodes[p2].distance){
					nodes[p2].distance = tmp2;
					nodes[p2].from = p1;
				}
			}
		}

		p1 = -1;
		int tmp;
		tmp = INT_MAX;
		for (int i=0; i<n; i++){
			if (nodes[i].visited==false && nodes[i].distance<tmp){
				p1 = i;
				tmp = nodes[i].distance;
			}
		}
	}
	return 0;
}

int resultout(vb &nodes){
	int n = nodes.size();
	for (int i=0; i<n; i++){
		cout<<i<<" "<<nodes[i].distance<<endl;
	}
	return 0;
}

int main(void){

	int n;
	cin>>n;
	vvi G(n, vi(n));
	vb nodes(n);

	make_graph(G, nodes);

	Shortest_Path(G, nodes);

	resultout(nodes);

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
 
using namespace std;
 
struct adja {
    int v;
    int c;
};
 
int n;
vector<adja> g[10000];
int d[10000];
 
void search() {
    fill_n(d, n, 1 << 20);
    queue<int> q;
    q.push(0);
    d[0] = 0;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int i = 0, s = g[u].size(); i < s; ++i) {
            if (d[g[u][i].v] > d[u] + g[u][i].c) {
                d[g[u][i].v] = d[u] + g[u][i].c;
                q.push(g[u][i].v);
            }
        }
    }
}
 
int main() {
    int u, k, v, c;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        g[u].resize(k);
        for (int j = 0; j < k; ++j) {
            cin >> g[u][j].v >> g[u][j].c;
        }
    }
    search();
    for (int i = 0; i < n; ++i) {
        cout << i << " " << d[i] << endl;
    }
 
    return 0;
}

C++: #include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
typedef long long int ll;
using namespace std;

const int MAX_V = 10000;
const int INF=1e9;

int cost[MAX_V][MAX_V];
int d[MAX_V];
bool used[MAX_V];
int n;

void dijkstra(int s){
  fill(d,d+n,INF);
  fill(used, used+n,false);
  d[s]=0;
  while(true){
    int v=-1;
    REP(u,n)
      if(!used[u] && (v==-1 || d[u]<d[v]))
	v=u;
    if(v==-1) break;
    used[v]=true;
    REP(u,n) d[u]=min(d[u],d[v]+cost[v][u]);
  }
}

int main(){
  cin>>n;
  REP(i,n)REP(j,n) cost[i][j]=INF;
  REP(i,n){
    int u, k; cin>>u>>k;
    REP(j,k){
      int v,c;
      cin>>v>>c;
      cost[u][v]=c;
    }
  }
  dijkstra(0);
  REP(i,n){
    cout<<i<<" "<<d[i]<<endl;
  }
}

C++: #include <iostream>
#include <stdio.h>
#include <vector>

#define inf 500000
using namespace std;

int main() {
    int n, tmp, tmp2, kazu;
    cin >> n;
    vector<vector<int> > g(n);//与えられるグラフ

    //初期化
    vector <int> d(n,inf);
    for (int i = 1; i < n; ++i) {
        d[i] = inf;
    }

    //入力を受け取る
    for (int i = 0; i < n; ++i) {
        cin >> kazu;
        cin >> kazu;
        g[i].push_back(i);
        g[i].push_back(0);
        for (int j = 0; j < kazu; ++j) {
            cin >> tmp >> tmp2;
            g[tmp].push_back(i);
            g[tmp].push_back(tmp2);
        }
    }
/*
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < g[i].size(); ++j) {
            cout << g[i][j] << " ";
        }
        cout << endl;
    }
    */
    d[0]=0;
    bool flag = true;
    while(flag){
        flag = false;
        for (int i = 0; i < n; ++i) { // i 今最短経路を求めているノード
/*
            for (int l = 0; l < n; ++l) {
                cout << d[i] << " ";
            }
            cout << endl;
*/
            for (int j = 0; j < g[i].size()/2; ++j) { // i j の組でその２点間の重み
                //cout << i << " " << j << " " << d[i] << " " << d[j*2] << " " << g[i][i*2+1] << endl;
                if (d[i] > d[g[i][j*2]] + g[i][j*2+1]) {
                    d[i] = d[g[i][j*2]] + g[i][j*2+1];
                    flag = true;

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


    return 0;
}