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 <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e6
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int cmp(P a,P b){
        if(a.fi!=b.fi)
        return a.fi>b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n;
vector<pair<int,int> >adj[10001];//邻接表表示法
void dijkstra(){
    priority_queue<pair<int,int> > pq;
    int color[10001];
    int d[10001];
    for(int i=0;i<n;i++){
        d[i]=INF;
        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]==INF?-1:d[i])<<endl;
    }
}
//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    cin>>n;
    
    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;
            adj[u].push_back(make_pair(v,c));
        }
    }
    dijkstra();
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------

C++: #include<stdio.h>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<queue>
#include<functional>
using namespace std;
int main(){
	int s;
	int g;
	int a;
	int b;
	int f;
	int t;
	vector<int> n[10000];
	int nn[10000];
	vector<int> x[10000];
	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > >y;
	vector<pair<int, int> >::iterator yy;
	int z;
	int d[10000];
	int e;
	int c[10000];
	int p;
	int q;
	int zz;
	pair<int, int>pai;
	for (int i = 0; i < 10000; i++){
		d[i] = 1000000009;
		c[i] = 0;
	}
	scanf("%d", &a);
	for (int i = 0; i < a; i++){
		scanf("%d %d", &s, &b);
		for (int j = 0; j < b; j++){
			scanf("%d %d",&t, &e);
			if (s > t){
				n[s].push_back(t);
				n[t].push_back(s);
				nn[s]++;
				nn[t]++;
				x[s].push_back(e);
				x[t].push_back(e);
			}
		}
	}
	d[0] = 0;
	y.push(std::make_pair(d[0], 0));
	for (int i = 0; y.empty() == 0; i++){
		zz = 0;
		for (int j = 0; y.empty() == 0 && zz == 0; j++){
			pai = y.top();
			z = pai.second;
			if (c[z] == 0)zz++;
			else y.pop();
		}
		if (zz == 0)break;
		c[z] = 1;
		for (int j = 0; j < nn[z]; j++){
			if (d[z] + x[z][j] < d[n[z][j]])
			{
				d[n[z][j]] = d[z] + x[z][j];
				y.push(std::make_pair(d[n[z][j]], n[z][j]));
			}
		}
		y.pop();
	}
	for (int i = 0; i < a; i++){
		printf("%d %d\n",i, d[i]);
	}

	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(){
  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;
}
}

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

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <queue>
#include <string>

using namespace std;

const double PI = 3.14159265358979;

//int G[101][101];
int visited[10001];
int n;

int d[10001];


struct Vertex {
	int u;
	int weight;

	friend bool operator < (Vertex a, Vertex b) {
		return a.weight > b.weight;
	}
};

vector<Vertex> G[10001];

void dijkstra(int start) {

	priority_queue<Vertex> PQ;

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

	d[start] = 0;
	PQ.push(Vertex{ 0,0 });

	while (!PQ.empty()) {
		Vertex f = PQ.top();
		PQ.pop();
		int u = f.u;
		if (visited[u]) {
			continue;
		}
		else {
			visited[u] = 1;
		}

		//if (f.weight > d[u]) continue;

		
		for (int j = 0; j < G[u].size(); j++)
		{
			int v = G[u][j].u;
			if (!visited[v]) {
				if (d[u] + G[u][j].weight < d[v]) {
					PQ.push(Vertex{ v, d[u] + G[u][j].weight });
					d[v] = d[u] + G[u][j].weight;
				}
			}
		}
	}


}

int main() {
	
	
	cin >> 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;
			G[u].push_back(Vertex{ v, w });
		}
	}

	dijkstra(0);

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

	return 0;
}