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


#define MAX 100


using namespace std;


int main()
{
    int n;
    vector< vector<int> > adj(MAX, vector<int>(MAX, -1));
    cin >> n;
    for (int i = 0; i < n; i++) {
        int id, k;
        cin >> id >> k;
        for (int j = 0; j < k; j++) {
            int v, c;
            cin >> v >> c;
            adj[id][v] = c;
        }
    }

    vector<int> min_costs(MAX, INT_MAX);
    vector<bool> in_tree(MAX, false);
    vector<int> parent(MAX, false);

    min_costs[0] = 0;
    for (int tc = 0; tc < n; tc++) {
        int min_cost = INT_MAX;
        int closest_v = -1;
        for (int i = 0; i < n; i++) {
            if (min_cost > min_costs[i] && !in_tree[i]) {
                min_cost = min_costs[i];
                closest_v = i;
            }
        }

        in_tree[closest_v] = true;

        for (int i = 0; i < n; i++) {
            if (adj[closest_v][i] < 0)
                continue;

            int w = min_cost + adj[closest_v][i];
            if (!in_tree[i] && min_costs[i] > w) {
                min_costs[i] = w;
                parent[i] = min_cost;
            }
        }
    }

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

    return 0;
}

C++: #include"iostream"
#include"algorithm"
#include"cstdio"
#include"cstring"
#include"string"
#include"vector"
#include"queue"
#include"map"
#include"set"
#include"stack"
#include"cmath"
using namespace std;
#define INF 0xfffffff
const int maxn = 100000 + 10;
const int maxm = 500000 + 10;
int n, m;
int s,t;
int fir[maxn], nxt[maxm], to[maxm], val[maxm], cnt;
void add_edge(int u, int v, int w)
{
    nxt[++cnt] = fir[u];
    fir[u] = cnt;
    to[cnt] = v;
    val[cnt] = w;
}
struct Node 
{
    int d, id;
    Node(){}
    Node(int d, int id) : d(d), id(id){}
    bool operator < (const Node& rhs) const
      {
        return d > rhs.d;
      }
};
int dis[maxn], vis[maxn];
void Dijkstra(int s)
{
    for(int i = 1; i <= n; i++) dis[i] = INF;
    dis[s]=0;
    priority_queue<Node> Q;
    Q.push(Node(0,s));
    while(!Q.empty()) 
      {
        Node u = Q.top(); Q.pop();
        if(vis[u.id]) continue;
        vis[u.id] = 1;
        for(int e = fir[u.id]; e; e = nxt[e]) 
          {
            int v = to[e], w = val[e];
            if(u.d + w < dis[v]) 
              {
                dis[v] = u.d + w;
                Q.push(Node(dis[v],v));
              }
          }
      }
}
int main()
{
		cin >> m;
		for(int i=0; i<m; i++)
        {
			int k;
			memset(vis,0,sizeof(vis));
			scanf("%d%d",&n,&k);
			for(int j=0;j<k;j++)
			{
            int  b, c;
            cin >> b >> c;
            add_edge(n,b,c);
			}
			Dijkstra(0);
			printf("%d %d\n",n,dis[n]);
        }
    return 0;
}

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

#define INF 1000000

int n;
int cost[110][110], d[110];
bool used[110];

void dijkstra(int s){

  for(int i = 0;i < n;i++) d[i] = INF;
  for(int i = 0;i < n;i++) used[i] = false;
  
  d[s] = 0;
  
  while(true){
    int v = -1;
    
    for(int u = 0;u < n;u++){
      if(!used[u] && (v == -1 || d[u] < d[v])) v = u;
    }
    
    if(v == -1) break;
    used[v] = true;
    
    for(int u = 0;u < n;u++){
      d[u] = min(d[u], d[v] + cost[v][u]);
    }
  }
}

int main(){
  
  int u, k, v, c;
  
  cin >> n;
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      cost[i][j] = INF;
    }
  }
  for(int i = 0;i < n;i++){
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      cin >> v >> c;
      cost[u][v] = min(cost[u][v], c);
    }
  }
  
  dijkstra(0);
  
  for(int i = 0;i < n;i++) cout << i << " " << d[i] << endl;
  
  return 0;
}

C++: #include <cstdio>
#include <iostream>
using namespace std;
#define INF 0xfffffff
int dis[200][200];
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
            {
                if(i==j) 
				dis[i][j]=0;
                else dis[i][j]=INF;
            }
		for(int i=0;i<n;i++)
		{
			int a,b,c;
			scanf("%d",&a);
			int t;
			scanf("%d",&t);
			for(int j=0;j<t;j++)
			{
				scanf("%d %d",&b,&c);
				dis[a][b]=min(c,dis[a][b]);
			}
		}
		for(int k = 0; k < n; k++)  //枚举中间点（必须放最外层）
		  for(int i = 0; i < n; i++)  //枚举端点i
		    if(i != k)
		      for(int j = 0; j < n; j++)  //枚举端点j
		        if(i != j && j != k && dis[i][j] > dis[i][k] + dis[k][j])
		          dis[i][j] = dis[i][k] + dis[k][j];
		int f,g;
		f=0;g=0;
		dis[0][0]=0;
		for(g=0;g<n;g++)
		{
			printf ("%d %d\n",g,dis[f][g]);
		}
	}
}