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 <cstdio>
#include <iostream>
#define MAX_VERTEXES 100
#define NIL -1
#define INFTY 20000000// >100*100000

using namespace std;

//think easy make easy

int n;//num of vertexes(頂点)
int matrix_graph[MAX_VERTEXES+1][MAX_VERTEXES+1];//0オリジン
bool vertex_set[MAX_VERTEXES+1];///0オリジン
int current_mincost[MAX_VERTEXES+1];//現時点での各頂点への最小コスト
bool candidate[MAX_VERTEXES+1];//次にvertex_setに加える頂点の候補
int new_vertex;

void findNextVertex(){
	int min_tmp=INFTY;
	int next_tmp = NIL;
	
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i == new_vertex && vertex_set[j] == false){//わかりやすいプログラムほど処理もすくない.
				//無駄のないプログラムの方がわかりよい
				if(matrix_graph[i][j]+current_mincost[i] < current_mincost[j]
				   && matrix_graph[i][j] != NIL){
					   current_mincost[j]  = matrix_graph[i][j]+current_mincost[i];
					   candidate[j] = true;
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		if(candidate[i] == true && current_mincost[i] < min_tmp){
			min_tmp = current_mincost[i];
			next_tmp = i;
		}
	}
	vertex_set[next_tmp] = true;
	candidate[next_tmp] = false;
	new_vertex = next_tmp;
}

int main(){
	scanf("%d",&n);

	int v_num;
	int k;//v_numの出次数

	for(int i=0;i<n;i++){
		for(int j=0;j<=n;j++){
			matrix_graph[i][j] = NIL;
		}
	}

	for(int i=0;i<n;i++){
		scanf("%d",&v_num);
		scanf("%d",&k);

		for(int j=0;j<k;j++){
			int v_num2;
			int cst;
			scanf("%d",&v_num2);
			scanf("%d",&cst);
			matrix_graph[v_num][v_num2] = cst;
		}
	}

	for(int i=0;i<n;i++){
		vertex_set[i] = false;
		current_mincost[i] = INFTY;
	}
	/*確認用
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(j<n-1) printf("%d ",matrix_graph[i][j]);
			else printf("%d\n",matrix_graph[i][j]);
		}
	}
	*/

	for(int i=0;i<n;i++){
		candidate[i] = false;
	}

	vertex_set[0] = true;
	current_mincost[0] = 0;
	new_vertex = 0;

	for(int i=1;i<n;i++){
		//for(int j=0;j<n;j++){
			//cout <<" " <<vertex_set[j] ;
		//}
		cout <<endl;
		findNextVertex();
	}


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


	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
const int MAX = 100;
const int INF = 200000;
int n, G[MAX][MAX];
int dis[MAX];
bool book[MAX] = { false };
void init()
{
	for (int i = 0; i < n; i++)
		dis[i] = G[0][i];
	book[0] = true;
}
void dijkstra()
{
	for (int k = 1; k <= n - 1; k++)
	{
		int min = INF;
		int u;
		for (int j = 0; j < n; j++)
			if (dis[j] > 0 && dis[j] < INF && !book[j] && dis[j] < min)
			{
				min = dis[j];
				u = j;
			}
		book[u] = true;
		for (int v = 0; v < n; v++)
			if (!book[v] && dis[u]+G[u][v] < dis[v])
				dis[v] = dis[u] + G[u][v];
	}
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (i != j)
				G[i][j] = INF;
			else
				G[i][j] = 0;
	for (int i = 0; i < n; i++)
	{
		int u, d;
		cin >> u >> d;
		for (int j = 0; j < d; j++)
		{
			int v, w;
			cin >> v >> w;
			G[u][v] = w;
		}
	}
	init();
	dijkstra();
	for (int i = 0; i < n; i++)
		cout << i << " " << dis[i] << endl;
}

C++: #include <bits/stdc++.h>

int INF = 900000000;
using pii = std::pair<int, int>;
std::vector<std::vector<pii>> g;
std::vector<bool> visited; 
std::vector<int> c; 
std::priority_queue<pii, std::vector<pii>, std::greater<pii>> q;

int n, p, x, y;
int discard;


int main() {
    std::cin >> n;
    visited.assign(n, false);
    g.assign(n, std::vector<pii>(0));
    c.assign(n, INF);
    for (int i = 0; i < n; i++) {
        std::cin >> discard >> p;
        for (int k = 0; k < p; k++) {
            std::cin >> x >> y;
            g[i].push_back(std::make_pair(y, x));
        }
    }
    q.push(std::make_pair(0, 0));
    c[0] = 0;
    while (!q.empty()) {
        auto e = q.top();
        q.pop();
        for (int j = 0; j < g[e.second].size(); j++) {
            if (c[g[e.second][j].second] < g[e.second][j].first) {
                continue;
            }
            if (c[e.second]+g[e.second][j].first < c[g[e.second][j].second]) {
                c[g[e.second][j].second] = c[e.second]+g[e.second][j].first;
                q.push(g[e.second][j]);
            }
        }
    }
    for (int i = 0; i < n; i++) {
        std::cout << i << " " << c[i] << std::endl;
    }
}

C++: #include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;

#define M 10005
#define INF 0x3f3f3f3f

int d[M][M],a[M],n;
bool vis[M];

void dijkstra()
{
    printf("%d!\n",n);
    for(int i=0;i<n;i++){
        if(i == 0) a[i]=0;
        else a[i]=INF;
    }
    memset(vis,0,sizeof(vis));
    for(int i=0;i<n;i++){
        int mark=-1,minn=INF;
        for(int j=0;j<n;j++){
            if(!vis[j]&&a[j]<minn){
                minn=a[j];
                mark=j;
            }
        }
        vis[mark]=1;
        for(int j=0;j<n;j++){
            if(!vis[j]){
                a[j]=min(a[j],a[mark]+d[mark][j]);
            }
        }
    }
    for(int i=0;i<n;i++){
        printf("%d %d\n",i,a[i]);
    }
}

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