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++: //Single Source Shortest Path II
#include <iostream>
#include <vector>
#include <queue>
#include <climits>

using namespace std;

static const int N = 10000;
static const int WHITE = 0;
static const int BLACK = 1;
int n, colors[N], d[N];
vector<pair<int, int> > G[N];


void dijkstra() {
    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > PQ;
    for(int i = 0; i < N; i++) {
        colors[i] = WHITE;
        d[i] = INT_MAX;
    }
    d[0] = 0;
    PQ.push(make_pair(0, 0));
    while(!PQ.empty()) {
        pair<int, int> f = PQ.top();
        PQ.pop();
        int u = f.second;
        if(colors[u] == BLACK) continue;
        for(int i = 0; i < G[u].size(); i++) {
            if(d[G[u][i].first] > f.first + G[u][i].second) {
                d[G[u][i].first] = f.first + G[u][i].second;
                PQ.push(make_pair(d[G[u][i].first], G[u][i].first));
            }

        }
    }
}

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

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

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

#define INF (1 << 21)

int main() {
	int node_num;

	std::cin >> node_num;
	std::vector<std::vector<int> > node(node_num, std::vector<int>(node_num, -1));

	for (size_t i = 0; i < node.size(); i++) {
		int out, node_number;
		std::cin >> node_number >> out;
		for (int j = 0; j < out; j++) {
			int to, distance;
			std::cin >> to >> distance;
			node[node_number][to] = distance;
		}
	}

	std::vector<int> distance(node.size(), INF);
	std::stack<int> s;
	distance[0] = 0;

	s.push(0);
	while(!s.empty()) {
		int node_number = s.top(); s.pop();
		for (size_t j = 0; j < node[node_number].size(); j++) {
			if (node[node_number][j] != -1 && node[node_number][j] + distance[node_number] < distance[j]) {
				distance[j] = node[node_number][j] + distance[node_number];
				s.push(j);
			}
		}
	}

	for (size_t i = 0; i < distance.size(); i++) {
		std::cout << i << " " << distance[i] << std::endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second

vector<pair<int,int> >adj[10010];
priority_queue<pair<int,int> > pq;
int nodes[10010];

int main(){
	memset(nodes,-1,sizeof(nodes));
	int n,node,k,v,c;
	cin>>n;
	for (int i=0; i<n; ++i) {
		cin>>node>>k;
		for (int j=0; j<k; ++j) {
			cin>>v>>c;
			adj[node].push_back(make_pair(v,c));
		}
	}
	pq.push(make_pair(0,0));
	while(!pq.empty()){
		pair<int,int> cur=pq.top();
		pq.pop();
		if(nodes[cur.se]!=-1){//kalo udh didatengin
			continue;
		}
		else nodes[cur.se]=-cur.fi;
		for(int i=0;i<adj[cur.se].size();i++){
			pq.push(make_pair(-adj[cur.se][i].se+cur.fi,adj[cur.se][i].fi));
		}
	}
	for (int i=0; i<n; ++i) {
		cout<<i<<" "<<nodes[i]<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

const int MAX = 10010;
const int INF = INT_MAX;

int n;
int dist[MAX];
typedef pair<int, int> VC;
typedef pair<int, int> VD;
vector< vector<VC> > G;

void dijkstra(int s)
{
  priority_queue<VD, vector<VD>, function<bool(VD, VD)>> que(
    [](VD a, VD b) { return a.second >= b.second; }
  );

  dist[s] = 0;
  que.push(make_pair(s, dist[s]));
  while (!que.empty()) {
    VD vd= que.top(); que.pop();
    int u = vd.first, d = vd.second;
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i].first, c = G[u][i].second;
      if (dist[v] > d + c) {
        dist[v] = d + c;
        que.push(make_pair(v, dist[v]));
      }
    }
  }
}

int main()
{
  cin >> n;

  fill(dist, dist+n, INF);
  G = vector< vector<VC> >(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(make_pair(v, c));
    }
  }

  dijkstra(0);

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

  return EXIT_SUCCESS;
}

C++: #include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#define P pair<int, int>

using namespace std;
const int MAX = 1<<30;

int main(){
  int n, d[10009];
  vector<P> G[10009];
  queue<int> Q;
  cin >> n;
  for(int i=0;i<n;i++){
    int u, k, v, c;
    cin >>u >> k;
    for(int j=0;j<k;j++){
      cin >> v >> c;
      G[u].push_back(P(v, c));
    }
    d[i] = MAX;
  }
  d[0] = 0;
  Q.push(0);
  while(!Q.empty()){
    int cur = Q.front();Q.pop();
    for(int i=0;i<G[cur].size();i++){
      int next = G[cur][i].first, weight = G[cur][i].second;
      if(weight + d[cur]< d[next]){
        d[next] = weight + d[cur];
        Q.push(next);
      }
    }
  }
  for(int i=0;i<n;i++)cout << i << ' ' << d[i] << endl;
}

C++: //
// Created by yuu on 2019-06-20.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>

using namespace std;

#define MAX 10010
#define INF 1<<20

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

void dijkstra(int start){
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> PQ;
    int d[MAX];
    int check[MAX];
    for (int i = 0; i < N; ++i) {
        d[i] = INF;
        check[i] = -1;
    }

    d[0] = 0;
    check[0] = 0;
    PQ.push(make_pair(0, start));

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

        //　接続先が小さい
        if (d[u] < f.first)continue;

        for (int i = 0; i < adj[u].size(); ++i) {
            int v = adj[u][i].first;
            if (check[v] == 1)continue;

            if (d[v] > d[u] + adj[u][i].second) {
                d[v] = d[u] + adj[u][i].second;
                PQ.push(make_pair(d[v], v));
                check[v] = 0;
            }
        }

    }

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

int main(void){
    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(0);






    return 0;
}