Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

var infty = 1000000000

type DirectedGraphNodeID int

type DirectedGraphNode struct {
	key         DirectedGraphNodeID
	adjacents   []*DirectedGraphNode
	costs       []int
	distance    int
	predecessor *DirectedGraphNode
}

func newDirectedGraph(nNodes int) *DirectedGraph {
	graph := DirectedGraph{}
	graph.nodes = make([]*DirectedGraphNode, nNodes)
	for i := 0; i < nNodes; i++ {
		node := DirectedGraphNode{}
		node.key = DirectedGraphNodeID(i)
		node.distance = infty
		graph.nodes[i] = &node
	}
	return &graph
}

type DirectedGraph struct {
	nodes []*DirectedGraphNode
}

func (g *DirectedGraph) setAdjacency(i, j DirectedGraphNodeID, cost int) {
	g.nodes[i].adjacents = append(g.nodes[i].adjacents, g.nodes[j])
	g.nodes[i].costs = append(g.nodes[i].costs, cost)
}

func (g *DirectedGraph) print() {
	for i := 0; i < len(g.nodes); i++ {
		node := g.nodes[i]
		key := node.key
		strings := []string{strconv.Itoa(int(key)), strconv.Itoa(node.distance)}
		for j := 0; j < len(node.adjacents); j++ {
			nodeJ := fmt.Sprintf("(%v, %v)", node.adjacents[j].key, node.costs[j])
			strings = append(strings, nodeJ)
		}
		fmt.Printf("%v\n", strings)
	}
}

func (g *DirectedGraph) relaxEdge(l, r *DirectedGraphNode, w int) {
	if r.distance > l.distance+w {
		// fmt.Printf("%v -> %v, %v\n", l.key, r.key, l.distance+w)
		r.distance = l.distance + w
		r.predecessor = l
	}
}

func main() {
	scanner.Split(bufio.ScanWords)

	nNodes := nextInt()
	graph := newDirectedGraph(nNodes)

	for i := 0; i < nNodes; i++ {
		iNode := DirectedGraphNodeID(nextInt())
		nAdjacent := nextInt()
		for j := 0; j < nAdjacent; j++ {
			jNode := DirectedGraphNodeID(nextInt())
			cost := nextInt()
			graph.setAdjacency(iNode, jNode, cost)
		}
	}

	graph.nodes[0].distance = 0
	for iNode := 0; iNode < nNodes; iNode++ {
		for iLeft := 0; iLeft < len(graph.nodes); iLeft++ {
			nodeLeft := graph.nodes[iLeft]
			for iRight := 0; iRight < len(nodeLeft.adjacents); iRight++ {
				nodeRight := nodeLeft.adjacents[iRight]
				cost := nodeLeft.costs[iRight]
				graph.relaxEdge(nodeLeft, nodeRight, cost)
			}
		}
	}

	// graph.print()

	for iNode := 0; iNode < len(graph.nodes); iNode++ {
		node := graph.nodes[iNode]
		fmt.Println(node.key, node.distance)
	}
}

C++: #include<iostream>
#include<vector>
#include<queue>
#define INF 1000000000

using namespace std;

struct vEdge {
	int adj;
	vector<int> weight;
	vector<int> tovtx;
	vEdge() {}

	void setadj(int a) { adj = a; }

	void setnum(int w, int n2) {
		weight.push_back(w); tovtx.push_back(n2);
	}
};

void dijkstra0(const vector<vEdge>& vedge, vector<int>& cost) {
	int mindex, min, temp, v,w, size = vedge.size(), count = 1;
	vector<bool> optimum(size, false);
	queue<int> qdata;
	cost.at(0) = 0; optimum.at(0) = true;

	while (count < size) {
		mindex = -1; min = INF;
		for (int i = 0; i < size; i++) if (optimum.at(i)) {
			for (int j = 0; j < vedge.at(i).adj;j++){
				v = vedge.at(i).tovtx.at(j);
				if (!optimum.at(v)) {
					w = vedge.at(i).weight.at(j);
					temp = cost.at(i) + w;
					if (temp < min) {
						min = temp;
						mindex = v;
					}
					if (temp < cost.at(v)) cost.at(v) = temp;
				}
			}
		}
		optimum.at(mindex) = true;
		count++;
	}

}

int main(void) {
	int size, num, adj, w, n2;
	cin >> size;

	vector<int> cost(size, INF);
	vector<vEdge> vedge(size);

	for (int i = 0; i < size; i++) {
		cin >> num >> adj;
		vedge.at(num).setadj(adj);
		for (int j = 0; j < adj; j++) {
			cin >> n2 >> w;
			vedge.at(num).setnum(w, n2);
		}
	}
	dijkstra0(vedge, cost);

	for (int i = 0; i < size; i++) cout << i << " " << cost.at(i) << endl;
	return 0;

}

C++: #include<bits/stdc++.h>
#define INF 0x3f3f3f3f 
using namespace std;
const int maxn = 11111;
int n, m;
struct edge
{
	int v, cost;
	edge(int _v=0,int _cost=0):v(_v),cost(_cost){}
};
vector<edge> g[maxn];
bool book[maxn];
int dis[maxn];
void myinit()
{
	memset(book, 0, sizeof(book));
	for (int i = 0; i < maxn; i++)
	{
		g[i].clear();
	}
	fill(dis, dis + maxn,INF);
}
void SPFA(int s)
{
	queue<int> q;
	q.push(s);
	book[s] = 1;//加入队列并标记 
	while (!q.empty())
	{
		int temp = q.front();
		q.pop();
		book[temp] = 0;//弹出队列并取消标记 
		for (int i = 0; i < g[temp].size(); i++)
		{
			if (g[temp][i].cost + dis[temp] < dis[g[temp][i].v])//比较 
			{
				dis[g[temp][i].v] = g[temp][i].cost + dis[temp];//更新路径 
				if (!book[g[temp][i].v])//若该点不在队列 
				{
					q.push(g[temp][i].v);
					book[g[temp][i].v] = 1;
				}
			}
		}
	}
}
void addedge(int u, int v, int w)
{
	g[u].push_back(edge(v, w));
}
int main()

{
	cin >> n;
	m = 0;
	myinit();
	for (int i = 0;i < n;i++)
	{
		int ve, en, co;
		int k;
		cin >> ve >> k;
		for (int j = 0;j < k;j++)
		{
			cin >> en >> co;
			addedge(ve, en, co);
		}
	}
	dis[0] = 0;
	SPFA(0);
	for (int i = 0;i < n;i++)
		cout << i << " " << dis[i] << endl;
	return 0;
}

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

#define INF 1000000 //极大的数 
const int N = 1009;

int d[N],v[N],w[N][N]; //d[i]为起始点到i的最短路径   v[i]为标记数组    w[x][y]表示边(x,y)的长度. 
int main(){
	int n,m,a,b,c,beg,end;
	while((scanf("%d",&n))!=EOF){
		memset(w,0,sizeof(w));
		memset(d,0,sizeof(d));
		memset(v,0,sizeof(v));
		for(int i=0;i<n;i++){
			scanf("%d%d",&a,&m);
			for(int j=0;j<m;j++){
				scanf("%d%d",&b,&c);
				w[i][b] = w[b][i] = c;
			}
		}
		for(int i=0;i<n;i++) d[i] = (i==0?0:INF);
		for(int i=0;i<n;i++){
			int x,a = INF; 
			for(int y=0;y<n;y++)
				if(!v[y]&&d[y]<=a) a = d[x=y];
				v[x] = 1;
		for(int j=0; j<n; j++)
                if(!v[j] && w[x][j] && d[x]+w[x][j] < d[j])
                    d[j] = d[x]+w[x][j];
		}
		for(int i=0;i<n;i++){
			printf("%d %d\n",i,d[i]);
		}
	}	
}

C++: #include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

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

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

    d[0] = 0;
    color[0] = GRAY;
    while(1)
    {
        minv = INFTY;
        int u = -1;
        for(int i=0; i<n; i++)
        {
            if(minv > d[i] && 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 && 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;
    }
}

int main()
{
    cin >> n;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++) M[i][j] = INFTY;
    }

    int k, c, u, v;
    for(int i=0; i<n; i++)
    {
        cin >> u >> k;
        for(int j=0; j<k; j++)
        {
            cin >> v >> c;
            M[u][v] = c;
        }
    }
    dijkstra();
    return 0;
}

C++: #include<iostream>
int main(){
  int u,k,C,V,A[1000][1000],D[1000][1000],n;
  std::cin >> n;
  for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j] = 200001;
  for(int i=0;i<n;i++){     std::cin >> u >> k;
    for(int j=0;j<k;j++){   std::cin >> V >> C;
      D[u][V] = C;}}
  for(int i=0;i<n;i++)D[i][i] = 0;
  for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j]= std::min(D[i][j],D[i][k] + D[k][j]);
  for(int i=0;i<n;i++)std::cout << i << " " << D[0][i] << std::endl;
  return 0;
}