Go: package main

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

const (
	white int = iota
	gray
	black
)

type node struct {
	id     int
	parent int
	edge   []int
	weight []int
	color  int
}

type graph struct {
	nodes    []node
	distance []int
}

var infty = 1 << 32
var null = -1

func constructgraph() *graph {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)

	g := &graph{make([]node, n), make([]int, n)}

	for i := 0; i < n; i++ {
		id := nextInt(sc)
		edges := nextInt(sc)
		n := node{}
		n.id = id
		n.edge = make([]int, edges)
		n.weight = make([]int, edges)
		n.color = white
		for j := 0; j < edges; j++ {
			to := nextInt(sc)
			w := nextInt(sc)
			n.edge[j] = to
			n.weight[j] = w
		}
		g.nodes[id] = n
	}
	return g
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func (g *graph) preparedijkstra(s int) {
	for i := 0; i < len(g.nodes); i++ {
		g.nodes[i].color = white
		g.nodes[i].parent = null
		g.distance[i] = infty
	}
	g.distance[s] = 0
}

func (g *graph) dijkstra(s int) []int {
	g.preparedijkstra(s)

	for {
		var u int
		mincost := infty
		for i, d := range g.distance {
			if g.nodes[i].color != black && mincost > d {
				mincost = d
				u = i
			}
		}

		if mincost == infty {
			break
		}

		g.nodes[u].color = black

		for i, e := range g.nodes[u].edge {
			if g.nodes[e].color != black {
				if g.distance[e] > g.distance[u]+g.nodes[u].weight[i] {
					g.distance[e] = g.distance[u] + g.nodes[u].weight[i]
					g.nodes[e].parent = u
					g.nodes[e].color = gray
				}
			}
		}
	}
	return g.distance
}

func printShortestPath(d []int) {
	for i, v := range d {
		fmt.Printf("%d %d\n", i, v)
	}
}

func main() {
	g := constructgraph()
	d := g.dijkstra(0)
	printShortestPath(d)
}

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

#define INFTY (1 << 30)

//???????????????
enum Color {
	WHITE,
	GRAY,
	BLACK,
};


//SSSP
void Dijkstra(int verValWeight[][100], int verNum) {

	//???????¨????
	int distance[100];
	Color color[100];
	int parent[100];
	for (int i = 0; i < verNum; i++) {
		color[i] = WHITE;
		distance[i] = INFTY;
		parent[i] = -1;
	}
	distance[0] = 0;

	//SSSP??????
	while (true) {

		//??°??¬????????????????????????????°?????????????????????¶
		int min_cost = INFTY;
		int subScript;
		for (int i = 0; i < verNum; i++) {
			if (color[i] != BLACK && distance[i] < min_cost) {
				min_cost = distance[i];
				subScript = i;
			}
		}

		//??????
		if (min_cost == INFTY)
			break;

		//?????????????????????
		color[subScript] = BLACK;

		//??£??\?????°??¬??????
		for (int i = 0; i < verNum; i++) {
			if (color[i] != BLACK && verValWeight[subScript][i] != INFTY) {
				if (distance[subScript] + verValWeight[subScript][i] < distance[i]) {
					distance[i] = distance[subScript] + verValWeight[subScript][i];
					parent[i] = subScript;
					color[i] = GRAY;
				}
			}
		}
	}

	//??????
	int weight_sum = 0;
	for (int i = 0; i < verNum; i++) {
		cout << i << " " << distance[i] << endl;
	}
}


int main() {

	int verNum;
	int verValWeight[100][100];
	int parent[100];

	//???????¨????
	cin >> verNum;
	for (int i = 0; i < verNum; i++)
		for (int j = 0; j < verNum; j++)
			verValWeight[i][j] = INFTY;

	//??\?????????
	for (int i = 0; i < verNum; i++) {
		int verVal, outNum;
		cin >> verVal >> outNum;
		for (int j = 0; j < outNum; j++) {
			int outVerVal, weight;
			cin >> outVerVal >> weight;
			verValWeight[i][outVerVal] = weight;
		}
	}

	//SSSP
	Dijkstra(verValWeight, verNum);

	return 0;
}

C++: #include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;
typedef vector<map<lli,lli> > graph;

lli n;
graph g;
lli u,k,v,c;
priority_queue<pll,vector<pll>,greater<pll> > q;
vbl vis;
vll ans;

int main(){
    cin >> n;
    g = graph(n);
    for(lli i = 0;i < n;i++){
        cin >> u >> k;
        for(lli i = 0;i < k;i++){
            cin >> v >> c;
            g[u][v] = c;
        }
    }
    vis = vbl(n);
    ans = vll(n);
    q.push(pll(0,0));
    while(!q.empty()){
        lli d = q.top().first;
        lli p = q.top().second;
        q.pop();
        if(vis[p]) continue;
        vis[p] = true;
        ans[p] = d;
        for(auto itr = g[p].begin();itr != g[p].end();itr++){
            if(!vis[itr->first]) q.push(pll(d+itr->second,itr->first));
        }
    }
    for(lli i = 0;i < n;i++) cout << i << " " << ans[i] << endl;
    return 0;
}

C++: #include <iostream>

using namespace std;

const int MAX=100;
const int INFTY=(1<<21);
const int WHITE=0;
const int GRAY=1;
const int BLACK=2;

int M[MAX][MAX];
int n;

void dijkstra(){
    int u,minv;
    int color[MAX],d[MAX];

    for(int i=0;i<n;i++){
        d[i]=INFTY;
        color[i]=WHITE;
    }

    d[0]=0;

    while(true){
        minv=INFTY;
        u=-1;
        for(int i=0;i<n;i++){
            if(minv>d[i] and color[i]!=BLACK){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1) break;
        color[u]=BLACK;
        for(int v=0;v<n;v++){
            if(color[v]!=BLACK and M[u][v]!=INFTY){
                if (d[v]>d[u]+M[u][v]){
                    d[v]=d[u]+M[u][v];
                    color[v]=GRAY;
                }
            }
        }
    }

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

    return;
}

int main()
{
    cin>>n;

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int e; cin>>e;
            M[i][j]= (e==-1)? INFTY:e;
        }
    }

    dijkstra();
}

C++: //
//  main.cpp
//  单元最短路径
//
//  Created by 陆昱珉 on 2018/12/26.
//  Copyright © 2018 Lu. All rights reserved.
//

//dijkstra algorithm

#include <stdio.h>
#define INF 999999

int n, k;
int color[3000], d[3000];
int map[3000][3000];

int dijkstra(int s)
{
    for(int i = 0; i < n; i ++)
    {
        d[i] = INF;
    }
    d[s] = 0;
    while(1)
    {
        int min = INF;
        int u = -1;
        for(int i = 0; i < n; i ++)
        {
            if(min > d[i] && color[i] != 1)
            {
                u = i;
                min = d[i];
            }
        }
        if(u == -1)
            break;
        color[u] = 1;//染色，以防后面重复使用
        for(int i = 0; i < n; i ++)
        {
            if(color[i] != 1 && map[u][i] != INF)
                if(d[i] > d[u] + map[u][i])
                    d[i] = d[u] + map[u][i];
        }
    }
    return 0;
}

int main(void)
{
    int x, y, v;
    scanf("%d", &n);
    for(int i = 0; i < n; i ++)
        for(int j = 0; j < n; j ++)
            map[i][j] = INF;
    for(int i = 0; i < n; i ++)
    {
        scanf("%d%d", &x, &k);
        for(int j = 0; j < k; j ++)
        {
            scanf("%d%d", &y, &v);
            map[x][y] = v;
        }
    }
    dijkstra(0);
    
    for(int i = 0; i < n; i ++)
    {
        if(d[i] != INF)
            printf("%d %d", i, d[i]);
        printf("\n");
    }
    return 0;
}