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<cstring>
#include<algorithm>
using namespace std;

int x[10000][2000];
int x2[10000][2000];
int y[10000];
int z[10000];

int main() {
	memset(x, 1, sizeof(x));
	memset(y, 1, sizeof(y));
	int n, a, b, c, d, e;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		for (int i = 0; i < b; i++) {
			cin >> c >> d;
			x[a][z[a]] = c;
			x2[a][z[a]] = d;
			z[a]++;
		}
	}
	y[0] = 0;
	e = min(n, 1600);
	for (int i = 0; i < e; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < z[j]; k++) {
				y[x[j][k]] = min(y[x[j][k]], y[j] + x2[j][k]);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << i << ' ' << y[i] << endl;
	}
	return 0;
}

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

#define MAX 10000
#define INF INT_MAX
#define WHITE 0
#define GRAY 1
#define BLACK 2

vector<pair<int, int> > M[MAX];
int n;
int col[MAX];
int d[MAX];

void init() {
	for (int i = 0; i < n; i++) {
		col[i] = WHITE;
		d[i] = INF;
	}
}
void input() {
	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));
		}
	}
}
void dijkstra(int s) {
	d[s] = 0;
	priority_queue<pair<int, int> > PQ;
	PQ.push(make_pair(d[s] * (-1), s));
	col[s] = GRAY;
	while (!PQ.empty()) {
		pair<int, int> f = PQ.top();
		PQ.pop();
		int u = f.second;
		col[u] = BLACK;
		if (d[u] < f.first * (-1))
			continue;
		for (int j = 0; j < M[u].size(); j++) {
			int v = M[u][j].first;
			if (col[v] != BLACK) {
				if (d[u] + M[u][j].second < d[v]) {
					d[v] = d[u] + M[u][j].second;
					col[v] = GRAY;
					PQ.push(make_pair(d[v] * (-1), v));
				}
			}
		}
	}
}
void output() {
	for (int i = 0; i < n; i++) {
		cout << i << " " << d[i] << endl;
	}
}

int main() {
	cin >> n;
	init();
	input();
	dijkstra(0);
	output();
	return 0;
}

C++: #include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;

int INF=1000000001;

typedef struct edge{
  int to;
  int cost;
}edge;

int N,E;
vector <edge> G[100001];
int mincost[100000];

void dikstra(){
  //priority_queue?????£?¨?
  typedef pair<int, int> P;
  priority_queue<P, vector<P>, greater<P> > Q;

  //mincost??????????????????????????????
  for(int i=0;i<N;i++){
    mincost[i]=INF;
  }
  mincost[0]=0;//??????????????°????????????0

  Q.push(P(0,0));
  //????????????????????????????????¬???
  while(!Q.empty()){
    int pos=Q.top().second;//position
    int pos_cost=Q.top().first;
    Q.pop();
    
    if(mincost[pos] < pos_cost ){
      continue;
    }

    for(int i=0;i<(int)G[pos].size();i++){
      edge e=G[pos][i];
      if(mincost[e.to]>pos_cost+e.cost){
        mincost[e.to]=pos_cost+e.cost;
        Q.push(P(mincost[e.to], e.to));
      }
    }
      
  }
  for(int i=0;i<N;i++){
      cout<<i<<' '<<mincost[i]<<endl;
    }
}

int main(){
  cin>>N;
  for(int i=0;i<N;i++){
    int id, k;
    cin >> id >> k;
    for(int j=0;j<k;j++){
      edge e;
      cin >> e.to >> e.cost;
      G[id].push_back(e);
    }
  }
  dikstra();
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const int MAX = 10005;

vector<pair<int, int>> to[MAX];
bool seen[MAX];
int d[MAX], n;

void dijkstra(int u) {
  d[u] = 0;
  priority_queue<pair<int, int>> pq;
  pq.push(make_pair(0, 0));
  pair<int, int> p;
  while (!pq.empty()) {
    p = pq.top();
    pq.pop();
    seen[p.second] = true;

    for (pair<int, int> e: to[p.second]) {
      if (seen[e.second]) continue;
      if (d[p.second] + e.first < d[e.second]) {
        d[e.second] = d[p.second] + e.first;
        pq.push(make_pair(-d[e.second], e.second));
      }
    }
  }
}

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

  rep(i, n) {
    seen[i] = false;
    d[i] = INF;
  }

  dijkstra(0);

  rep(i, n) cout << i << " " << d[i] << endl;

  
  return 0;
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};



int main() {
    int N;
    cin >> N;
    std::vector<vector<int> > G(N, vector<int>(N, 100000000));
    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][v] = c;
        }
    }

    for (int i = 0; i < N; i++) {
        G[i][i] = 0;
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                G[i][j] = std::min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }

    for (int i = 0; i < N; i++) {
        cout << i << " " << G[0][i] << endl;
    }
    return 0;
}