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 <vector>
#include <queue>
#include <iostream>

using namespace std;

#define NODE_NUM 10000
#define INF 100000

typedef struct Node {
    //????????????????????????????????????
    int idx;
    
    // ????????????????????????????????¨??????????????±
    vector<int> edges_to;    // ?????¨???????????\?¶??????????????????????
    vector<int> edges_cost;  // ?????¨??????????????????
    
    // ??????????????????????????????????????????
    bool done;  // ?¢??????????????????????
    int cost;   // ????????????????????????????????§??????????????????????°??????????
}Node;

Node nodes[NODE_NUM];


struct NodeCompare
{
    bool operator()(const Node &t1, const Node &t2) const
    {
        //?????????????????????????????????????????????????????????????????????????????´?????????????????????????????????
        return t1.cost > t2.cost;
    }
};

void Dijkstra(int node_num, int start_node){
    
    // ?????????
    for (int i =0 ; i < node_num; i++) {
        nodes[i].done = false;
        nodes[i].cost = INF;
        nodes[i].idx = i;
    }

    //????????????????????\???????°?????????????????????????
    priority_queue<Node, vector<Node>, NodeCompare> q;
    
    // ????????????????????????????????????0
    nodes[start_node].cost = 0;
    q.push(nodes[start_node]);
    
    // ??¢?????´???????????????
    while(!q.empty()){
        
        // ?¢????????????????????????????
        Node doneNode = q.top();
        q.pop();
        
        //???????¢?????????????????????????????????????????????¨??±?????????
        if (doneNode.done) continue;
        
        // ?¢????????????°????????????
        nodes[doneNode.idx].done = true;
        
        // ??\?¶?????????????????????±?????´??°??????
        for(int i = 0; i < doneNode.edges_to.size(); i++){
            
            int to = doneNode.edges_to[i];
            int cost = doneNode.cost + doneNode.edges_cost[i];
            if( nodes[to].cost == INF || cost < nodes[to].cost){
                nodes[to].cost = cost;
                if(!nodes[to].done){
                    q.push(nodes[to]);
                }
            }
        }
    }
}

int main( ){
    
    int i, j, n, k, v, c, u;
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%d %d",&u,  &k);
        
        for (j =0 ; j < k; j++) {
            scanf("%d %d", &v, &c);
            nodes[u].edges_cost.push_back(c);
            nodes[u].edges_to.push_back(v);
        }
    }
    
    Dijkstra(n, 0);
    
    for (i=0; i<n; i++) {
        printf("%d %d\n", i, nodes[i].cost);
    }
    
    return 0;
}

C++: // ALDS1_12_C.cpp
// Graph II - Single Source Shortest Path II
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;

struct Node {
    int v;
    int c;
    Node(int v, int c): v(v), c(c) {}
};

const int maxN = 10000;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int INF = (1<<21);
vector<Node> G[maxN];
vector<int> dist(maxN, INF);
vector<int> p(maxN);
vector<int> color(maxN, WHITE);
priority_queue<pair<int, int>> mq;
int n;

void dijkstra(int x)
{
    dist[x] = 0;
    p[x] = -1;
    mq.push({-dist[x], x});
    while(!mq.empty()) {
        pair<int, int> P = mq.top();
        mq.pop();
        int mindist = -P.first;
        int u = P.second;
        if (color[u] == BLACK) continue;

        for (int i = 0; i < G[u].size(); i++) {
            if (color[u] == BLACK) continue;
            int v = G[u][i].v;
            int c = G[u][i].c;
            if (dist[u] + c < dist[v]) {
                dist[v] = dist[u] + c;
                p[v] = u;
                color[v] = GRAY;
                mq.push({-dist[v], v});
            }
        }
        color[u] = BLACK;
    }
}

int main()
{
//    freopen("in7.txt", "r", stdin);
//    freopen("out7.txt", "w", stdout);
    cin >> n;
    int u, k;
    int v, c;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v >> c;
            G[i].push_back(Node(v, c));
        }
    }
    dijkstra(0);
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i, dist[i]);
    }
    return 0;
}

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

using WNode = std::pair<uint32_t, uint32_t>;
using WGraph = std::vector<std::vector<WNode>>;
using rWNode = std::pair<uint32_t, uint32_t>;

int main() {
  uint32_t N = 0;
  std::cin >> N;
  WGraph G(N);
  for (size_t i = 0; i < N; i++) {
    uint32_t K = 0;
    std::cin >> i >> K;
    for (size_t j = 0; j < K; j++) {
      uint32_t node = 0, cost = 0;
      std::cin >> node >> cost;
      G[i].push_back({node, cost});
    }
  }

  const uint32_t start = 0;
  std::priority_queue<rWNode, std::vector<rWNode>, std::greater<rWNode>> Q;
  Q.push({0, start});
  std::vector<uint32_t> result(N, -1);
  std::vector<uint32_t> temp(N, -1);
  while (!Q.empty()) {
    uint32_t cost = Q.top().first, current = Q.top().second;
    Q.pop();

    if (result[current] <= cost) continue;
    result[current] = cost;

    for (auto &&g : G[current]) {
      if (result[g.first] != static_cast<uint32_t>(-1)) continue;
      if (temp[g.first] <= g.second + result[current]) continue;
      temp[g.first] = g.second + result[current];
      Q.push({g.second + result[current], g.first});
    }
  }

  for (size_t i = 0; i < N; i++) {
    std::cout << i << " " << result[i] << std::endl;
  }

  return 0;
}