Go: package main

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

const BIG_COST = 200000

const (
	ST_NOT_YET = iota
	ST_JOINED
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nNodes := scanInt(sc)

	costs := make([][]int, nNodes)
	graph := make([][]int, nNodes)

	states := make([]int, nNodes)
	costSums := make([]int, nNodes)

	for i := 0; i < nNodes; i++ {
		costs[i] = make([]int, nNodes)
		costSums[i] = BIG_COST
	}

	for i := 0; i < nNodes; i++ {
		u := scanInt(sc)
		k := scanInt(sc)
		graph[u] = make([]int, k)
		for d := 0; d < k; d++ {
			v := scanInt(sc)
			graph[u][d] = v
			costs[u][v] = scanInt(sc)
		}
	}

	costSums[0] = 0
	for {
		minCost := BIG_COST
		var u int

		for i, cost := range costSums {
			if states[i] != ST_JOINED && cost < minCost {
				minCost = cost
				u = i
			}
		}

		if minCost == BIG_COST {
			break
		}

		states[u] = ST_JOINED

		for _, v := range graph[u] {
			cost := minCost + costs[u][v]
			if cost < costSums[v] {
				costSums[v] = cost
			}
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i, cost := range costSums {
		fmt.Fprintf(w, "%d %d\n", i, cost)
	}
	w.Flush()
}

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

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;
}

C++: #include <iostream>
#include <vector>
#define INF 1e9
using namespace std;

int main(){
    //declaration and input
    int n;
    cin >> n;
    int u, k;
    vector<vector<int>> graph(n, vector<int>(n, INF));
    for (int i = 0; i < n; i++){
        cin >> u >> k;
        int v, c;
        for (int j = 0; j < k; j++){
            cin >> v >> c;
            graph[u][v] = c;
        }
    }
    vector<int> cost(n, INF);
    vector<int> parent_of(n, -1);
    vector<bool> is_visit(n, false);

    //Dijkstra
    //init
    cost[0] = 0;
    
    //loop
    while(true){
        int mincost = INF;
        int next = -1;
        for (int i = 0; i < n; i++){
            if (!is_visit[i] && cost[i] < mincost){
                mincost = cost[i];
                next = i;
            }
        }
        if (next == -1)
            break;
        is_visit[next] = true;
        for (int i = 0; i < n; i++){
            if (!is_visit[i] && graph[next][i] < INF){
                if (cost[next] + graph[next][i] < cost[i]){
                    cost[i] = cost[next] + graph[next][i];
                    parent_of[i] = next;
                }
            }
        }
    }

    //output
    for (int i = 0; i < n; i++)
        cout << i << ' ' << cost[i] << endl;
    return 0;
}