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 "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<vector<pair<int, int> > > vvp;
typedef vector<pair<int,int> > vp;
typedef vector<vector<int> > vvi;
typedef vector<int> vi;
typedef vector<vector<bool> > vvb;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<string, int> psi;
typedef pair<int, int> pii;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define yn(f) (f?"yes":"no")
#define YN(f) (f?"YES":"NO")
#define Yn(f) (f?"Yes":"No")
#define mod 1000000007
#define intmax 2147483647
#define intmin -2147483648
#define longmax 9223372036854775807
#define longmin -9223372036854775808
#define black 0
#define gray 127
#define white 255
int main() {
	int N;
	cin >> N;
	vvp A(N);
	for (int i = 0; i < N; i++)
	{
		int u,k;
		cin >> u>>k;
		for (int j = 0; j < k; j++)
		{
			int v, w;
			cin >> v >> w;
			A[u].push_back(make_pair(v,w));
		}
	}
	vi color(N,black);
	priority_queue<pii,vp,greater<pii> > pq;
	vi mincost(N,intmax);
	color[0] = gray;
	pq.push(make_pair(0,0));
	mincost[0] = 0;
	while (!pq.empty()) {
		pii minp = pq.top();
		pq.pop();
		color[minp.second] = white;
		if (mincost[minp.second]<minp.first) continue; 
		for (int i = 0; i < A[minp.second].size(); i++)
		{
			int u = A[minp.second][i].first;
			if (color[u]!=white&&mincost[u]>mincost[minp.second]+ A[minp.second][i].second) {
				mincost[u] = mincost[minp.second] + A[minp.second][i].second;
				pq.push(make_pair(mincost[u],u));
				color[u] = gray;
			}
		}
	}
	for (int i = 0; i < N; i++)
	{
		cout << i << " " << mincost[i] << endl;
	}
};

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1<<20)
#define PI (acos(-1))
#define MAX 10000
#define WHITE  0
#define GRAY  1
#define BLACK  2

int N;
vector< pair<int, int> > G[MAX]; // targetの先と、重みのペアが保存されている

void dijkstra(int s) { // sはスタート地点
    priority_queue<pair <int, int> > PQ;
    int color[MAX];
    int d[MAX]; // 最短距離を保存する

    for(int i=0; i<N; i++) {
        d[i] = INF;
        color[i] = WHITE;
    }

    d[0] = 0;
    PQ.push(make_pair(0, 0)); // d, vの順で入っている
    color[0] = GRAY;

    while (!PQ.empty()) {
        pair<int, int> f = PQ.top(); PQ.pop();
        int u = f.second;
        color[u] = BLACK;

        if (d[u] < f.first * (-1) ) continue;

        for (int j=0; j< G[u].size(); j++) {
            int v =  G[u][j].first; //　隣接する頂点の取り出し
            if ( color[v] == BLACK) continue;
            if ( d[v] > d[u] + G[u][j].second ) {
                d[v] = d[u] + G[u][j].second;
                PQ.push( make_pair(d[v] * (-1), v ));
                color[v] = GRAY;
            }
        }
    }
    for(int i=0; i<N; i++) {
        cout << i << " " << (d[i] == INF ? -1 : d[i])  << endl;
    }
}

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

    cin >> N;
    for(int i=0; i<N; i++) {
        cin >> u >> k;

        for(int j=0; j<k; j++) {
            cin >> v >> c;
            G[u].push_back(make_pair(v, c));
        }
    }

    dijkstra(0);
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int> > adj[MAX];

void dijkstra(void);

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

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

    dijkstra();

    return 0;
}

void dijkstra(void)
{
  priority_queue<pair<int, int> > PQ;
  int color[MAX];
  int d[MAX];
  for( int i = 0; i < n; i++)
    {
      d[i] = INFTY;
      color[i] = WHITE;
    }

  d[0] = 0;
  PQ.push(make_pair(0, 0));
  color[0] = GRAY;

  while( !PQ.empty() )
    {
      pair<int, int> f = PQ.top(); PQ.pop();
      int u = f.second;

      color[u] = BLACK;

      if( d[u] < f.first * (-1) ) continue;

      for( int j = 0; j < adj[u].size(); j++)
        {
          int v = adj[u][j].first;
          if( color[v] == BLACK ) continue;
          if( d[v] > d[u] + adj[u][j].second )
            {
              d[v] = d[u] + adj[u][j].second;
              PQ.push(make_pair(d[v] * (-1), v));
              color[v] = GRAY;
            }
        }
    }

  for( int i = 0; i < n; i++)
    {
      cout << i << " " << ( d[i] == INFTY ? -1 : d[i] ) << endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
const int maxx=10010;
const int infinity=1<<30;

int main() {
	int n,a,b,c,e;
	vector<pair<int, int> > A[maxx];
	bool flag[maxx];
	int d[maxx];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		for(int j=0;j<b;j++){
			cin>>c>>e;
			A[a].push_back(make_pair(c,e));
		}
	}
	for(int i=0;i<n;i++){
		flag[i]=false;
		d[i]=infinity;
	}
	priority_queue<pair<int,int> > PQ;
	d[0]=0;
	PQ.push(make_pair(0, 0));
	while(PQ.empty()==0){
		pair<int, int> u=PQ.top();
		PQ.pop();
		//cout<<u.first<<" "<<d[u.first]<<endl;
		flag[u.second]=true;
		int len=A[u.second].size();
		for(int i=0;i<len;i++){
			int v=A[u.second][i].first;
			if(flag[v]==false && d[u.second]+A[u.second][i].second<d[v]){
				d[v]=d[u.second]+A[u.second][i].second;
				PQ.push(make_pair(d[v]*(-1),v));
			}
		}
	}

	for(int i=0;i<n;i++) cout<<i<<" "<<(d[i]==infinity ? -1 : d[i])<<endl;

	return 0;
}