Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
type Node struct {
	cost int
	done bool
}

type Edge struct {
	to, cost int
}

const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	nodes := make([]Node, N)
	for i := 0; i < N; i++ {
		nodes[i].cost = INF
	}
	E := make([][]Edge, N)
	for i := 0; i < N; i++ {
		id, k := sc.nextInt(), sc.nextInt()
		for j := 0; j < k; j++ {
			to, cost := sc.nextInt(), sc.nextInt()
			E[id] = append(E[id], Edge{to, cost})
		}
	}
	nodes[0].cost = 0
	for {
		cur := 0
		minCost := INF
		for i := 0; i < N; i++ {
			n := nodes[i]
			if !n.done && n.cost < minCost {
				cur = i
				minCost = n.cost
			}
		}
		if minCost == INF {
			break
		}
		nodes[cur].done = true
		for i := 0; i < len(E[cur]); i++ {
			to, cost := E[cur][i].to, E[cur][i].cost+nodes[cur].cost
			if !nodes[to].done && cost < nodes[to].cost {
				nodes[to].cost = cost
			}
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprintln(wtr, i, nodes[i].cost)
	}
	wtr.Flush()
}

C++: #include <stdio.h>

#define MAX 100
#define INF 1000000000
#define w 0
#define x 1
#define z 2

int n, m[MAX][MAX];

void data(){
  int min,d[MAX],a[MAX],i,u;
  for(i = 0 ;i< n;i++){
    d[i] = INF;
    a[i] = INF;
  }
  d[0]=0;
  a[0]=x;
  while(1){
    min = INF;
    u = -1;
    for(i = 0;i<n;i++){
      if(min > d[i] && a[i] != z){
        u = i;
        min = d[i];
      }
    }
    if(u == -1) break;
    a[u] = z;
    for(i = 0;i<n;i++){
      if(a[i]!= z &&m[u][i] != INF){
        if(d[i] > d[u] + m[u][i]){
          d[i] = d[u] + m[u][i];
        }
      }
    }
  }
  int v;
  for(i = 0 ;i< n;i++){
    v = d[i];
    if(d[i] == INF) v = -1;
    printf("%d %d\n",i,v);
  }
}

int main(){
  scanf("%d",&n);
  int i,j,k,c,u,v;
  for(i = 0;i<n;i++){
    for(j = 0;j<n;j++){
      m[i][j] = INF;
    }
  }
  for(i = 0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j = 0;j<k;j++){
      scanf("%d %d",&v,&c);
      m[u][v] = c;
    }
  }
  data();
  return 0;
}

C++: #include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
#define INF 1<<21
int main()
{
	long long int min,n,u,k,v,c,dist[100][100],s,cost[100],t[100],l=1;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			dist[i][j]=INF;
			cost[i]=INF;
			t[i]=-1;
		}
	}
	min=INF;
	dist[0][0]=0;
	for(int i=1;i<=5;i++)
	{
		cin>>u;
		cin>>k;
		for(int i=1;i<=k;i++)
		{
			cin>>v>>c;
			dist[u][v]=c;
		}
	}
	s=0;
	cost[s]=0;
	while(l!=n)
	{
		for(int i=0;i<n;i++)
		{
			if(dist[s][i]!=INF)
			{
				if(cost[s]+dist[s][i]<cost[i])
				{
					cost[i]=cost[s]+dist[s][i];
				}
				
			}
		}
		t[s]=1;
		for(int i=1;i<n;i++)
		{
			if(cost[i]<min&&t[i]==-1)
			{
				min=cost[i];
				s=i;
			}
		}
		min=INF+1;
		l++;
	}
	for(int i=0;i<n;i++)
	{
		cout<<i<<" "<<cost[i]<<endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const int inf = 1e9;
// ダイクストラO(elogv)
struct edge{
  int to, cost;
  edge(int t, int c) {
    to = t, cost = c;
  }
};
typedef pair<int, int> P;
int N;
vector<edge> G[111];
int d[111];
void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> >que;
  FOR(i,1,N+1) d[i] = inf;
  d[s] = 0;
  que.push(P(0, s));
  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(auto &e : G[v]){
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin>>N;
  FOR(i,0,N){
    int u, k;
    cin >> u >> k;
    FOR(j,0,k){
      int v, c;
      cin >> v >> c;
      G[u].push_back(edge(v, c));
    }
  }
  dijkstra(0);
  FOR(i,0,N){
    cout << i << " " << d[i] << endl;
  }
}

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

//#define INF 2147483647
#define INF INT_MAX

using namespace std;

int n;
priority_queue<pair<int, int>,  deque<pair<int,int>>, greater<pair<int,int>>> q;
vector<vector<int>> c;
vector<int> d;


int input(){
  cin >> n;
  int u = 0, k = 0, v = 0;
  c.resize(n);
  for( int i = 0; i < n; i++ ){
    cin >> u >> k;
    c[u].resize(n, -1);
    for( int j = 0; j < k; j++ ){
      cin >> v;
      cin >> c[u][v];
    }
  }
  d.resize(n, INF);
  return 0;
}

int checkContinue(){
  for( int i = 0; i < n; i++ ){
    if( d[i] == INF ){ return 1; }
  }
  return 0;
}

int run(){
  q.emplace(pair<int,int>(0,0));
  while( checkContinue() ){
    pair<int, int> p = q.top();
    q.pop();
    if( d[p.second] < p.first ){ continue; }
    d[p.second] = p.first;
    for( int i = 0; i < n; i++ ){
      if( c[p.second][i] < 0 ){ continue; }
      q.push(pair<int,int>(p.first+c[p.second][i], i));
      // cout << p.first+c[p.second][i] << "," << i << endl;
    }
  }
  for( int i = 0; i < n; i++ ){
    cout << i << " " << d[i] << endl;
  }
  return 0;
}

int main(){
  input();
  run();
  return 0;
}