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;
#define int long long
typedef pair<int,int> P;
vector<vector<P> > G;
signed main(){
  int n;
  cin>>n;
  int INF=1LL<<55LL;
  G.resize(n);
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v,c;
      cin>>v>>c;
      G[u].push_back(P(v,c));
    }
  }
  int d[n];
  for(int i=0;i<n;i++) d[i]=INF;
  d[0]=0;

  priority_queue<P,vector<P>,greater<P> > q;
  d[0]=0;
  q.push(P(0,0));

  while(!q.empty()){
    P p=q.top();q.pop();
    int u=p.second,c=p.first;
    //cout<<u<<" "<<c<<endl;
    if(d[u]<c) continue;
    for(P e:G[u]){
      int v=e.first,w=e.second;
      if(d[v]>d[u]+w){
	d[v]=d[u]+w;
	q.push(P(d[v],v));
	//cout<<v<<":"<<d[v]<<endl;
      }
    }
  }
  
  for(int i=0;i<n;i++) cout<<i<<" "<<d[i]<<endl;
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<queue>

using namespace std;

#define N 10000

#define WHITE 0
#define GRAY 1
#define BLACK 2

static const int INFTY = (1<<20);
int n;

vector<pair<int,int> >adj[N];

void dijkstra(void);

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

  cin >> n;
  
  for(i = 0;i < n;i++){
    cin >> u >> k;
    
    for(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 i,j;
  int u,v;
  int d[N],color[N];
  
  for(i = 0;i < n;i++){
    color[i] = WHITE;
    d[i] = INFTY;
  }

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

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

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

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

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

C++: #include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

struct Node {
    int pos;
    int sum_cost;

    Node(int p, int c) {
        pos = p;
        sum_cost = c;
    }

    bool operator >(const Node &other) const {
        return sum_cost > other.sum_cost;
    }
};

struct Edge {
    int to_node;
    int cost;

    Edge(int n, int c) {
        to_node = n;
        cost = c;
    }
};

vector<vector<Edge>> adj; // 隣接行列
priority_queue<Node, vector<Node>, greater<Node>> pq; // ヒープ
int dist[10100];

int main() {
    int n; cin >> n;
    adj.resize(n);
    rep(i, n) {
        int u, k; cin >> u >> k;
        rep(j, k) {
            int v, c; cin >> v >> c;
            adj[u].emplace_back(Edge(v, c));
        }
    }

    // 初期化
    rep(i, n) {
        dist[i] = (i == 0) ? 0 : INT_INF;
        pq.push(Node(i, dist[i]));
    }

    while (!pq.empty()) {
        Node popped = pq.top();
        pq.pop();

        for (auto &edge: adj[popped.pos]) {
            Node next(edge.to_node, popped.sum_cost + edge.cost);
            if (next.sum_cost < dist[edge.to_node]) {
                pq.push(next);
                dist[edge.to_node] = next.sum_cost;
            }
        }
    }

    rep(i, n) {
        cout << i << ' ' << dist[i] << endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
static const int M = 10000;

int n;
vector<pair<int,int> > a[M];

void dijkstra(void);

int main(){
  int x,y,z,w,i,j;

  cin >> n;
  for(i = 0;i < n;i++){
    cin >> x >> y;
    for(j = 0;j < y;j++){
      cin >> z >> w;
      a[x].push_back(make_pair(z,w));
    }
  }
  dijkstra();

  return 0;
}

void dijkstra(void){
  priority_queue<pair<int,int> > PQ;
  int color[M],d[M],i,j,x,z;

  for(i = 0;i < n;i++){
    d[i] = 10000000;
    color[i] = 0; //0=white
  }
  d[0] = 0;
  PQ.push(make_pair(0,0));
  color[0] = 1; //1=gray

  while(!PQ.empty()){
    pair<int,int>f = PQ.top(); PQ.pop();
    x = f.second;
    color[x] = 2; //2=black
    if(d[x] < f.first * (-1)) continue;

    for(j = 0;j < a[x].size();j++){
      z = a[x][j].first;
      if(color[z] == 2) continue;
      if(d[z] > d[x] + a[x][j].second){
	d[z] = d[x] + a[x][j].second;
	PQ.push(make_pair(d[z] * (-1),z));
	color[z] = 1;
      }
    }
  }
  for(i = 0;i < n;i++){
    cout << i << " " << (d[i] == 10000000 ? -1 : d[i]) << endl;
  }
}