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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

static const int MAX = 10000;
static const int INFTY = (1<<20);   // pow(10,19);
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], d[MAX];
    rep(i, n){
        d[i] = INFTY;
        color[i] = WHITE;
    }
    d[0] = 0; color[0] = GRAY;
    PQ.push(make_pair(0, 0));

    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;

        rep(j,adj[u].size()){
            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;
                // priority_queueは、デフォルトで大きい値を優先するため-1をかける
                PQ.push(make_pair(d[v]*(-1), v));
                color[v] = GRAY;
            }
        }
    }
    rep(i,n){
        cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}

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

    dijkstra();

    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));  // priority_queue はデフォルトで大きい値を優先するため -1 を掛ける
                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;
    int i, j;

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

C++: #include <iostream>
#include <vector>
#include <queue>
#include <climits>

struct Node {
	int id;
	std::vector<int> edge_to;
	std::vector<int> edge_cost;
	bool done;
	int cost;
};

bool operator>(const Node& u, const Node& v) { return u.cost > v.cost; }
bool operator<(const Node& u, const Node& v) { return u.cost < v.cost; }
bool operator>=(const Node& u, const Node& v) { return u.cost >= v.cost; }
bool operator<=(const Node& u, const Node& v) { return u.cost <= v.cost; }
bool operator==(const Node& u, const Node& v) { return u.id == v.id; }
bool operator!=(const Node& u, const Node& v) { return u.id != v.id; }

void swap(int& x, int& y)
{
	int tmp = x;
	x = y;
	y = tmp;
}

int min(int x, int y)
{
	return x>y ? y : x;
}

int main()
{
	int n; std::cin >> n;
	
	Node* nodes = new Node[n];
	
	for (int i=0; i<n; i++) {
		nodes[i].done = false;
		nodes[i].cost = INT_MAX;
	}
	
	for (int i=0; i<n; i++) {
		int id, deg;
		std::cin >> id >> deg;
		nodes[i].id = id;
		for (int j=0; j<deg; j++) {
			int t, cost;
			std::cin >> t >> cost;
			nodes[i].edge_to.push_back(t);
			nodes[i].edge_cost.push_back(cost);
		}
	}
	
	std::priority_queue<Node, std::vector<Node>, std::greater<std::vector<Node>::value_type>> que;
	que.push(nodes[0]);
	nodes[0].cost = 0;
	
	while (!que.empty()) {
		Node v = que.top(); que.pop();
		int s = v.id;
		// std::cout << s << " " << nodes[s].cost << std::endl;
		nodes[s].done = true;
		for (int k=0; k<nodes[s].edge_to.size(); k++) {
			int t = nodes[s].edge_to[k];
			int cost = nodes[s].edge_cost[k];
			if (nodes[t].done) continue;
			if ( nodes[t].cost > nodes[s].cost + cost) {
				nodes[t].cost = nodes[s].cost + cost;
				que.push(nodes[t]);
			}
		}
	}
	
	for (int i=0; i<n; i++) {
		std::cout << nodes[i].id << " " << nodes[i].cost << std::endl;
	}
	
	delete[] nodes;
	
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<queue>
#include<utility>
#include<climits>
#include<algorithm>
using namespace std;
typedef int Cost;
typedef int Node;

void dijkstra(int start,   vector<vector< pair<Node,Cost> > > m){
  vector<Cost> costs(m.size());
  bool visited[m.size()];

  fill(costs.begin(),costs.end(),INT_MAX);
  fill(visited,visited+m.size(),false);
  
  priority_queue<pair<Cost,Node> ,vector<pair<Cost,Node> >, greater<pair<Cost,Node> > > q;
  q.push(make_pair(0,start));
  while(!q.empty()){
    Cost c = q.top().first;
    Node n = q.top().second;
    q.pop();
    if(!visited[n]){
      costs[n] = c;
      for(auto &x:m[n]){
        int node = x.first;
        int cost = x.second;
        q.push(make_pair(cost+c,node));
      }
      visited[n] = true;
    }
  }
  for(int i = 0;i < costs.size();i++){
    cout << i << ' ' << costs[i] << endl;
  }
}

int main(){
  int n;
  cin >> n;
  vector<vector< pair<Node,Cost> > > m(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;
      m[u].push_back(make_pair(v,c));
    }
  }
  dijkstra(0,m);
}