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 <cstdio>
#include <cctype>
#include <climits>
#include <vector>
#include <queue>
using namespace std;

#define si static inline
#define gcu getchar_unlocked
si int in() {
	int c, n = 0;
	bool minus = false;
	if ((c = gcu()) == '-') minus = true; else ungetc(c, stdin);
	while ((c = gcu()) >= '0' && c <= '9') n = 10 * n + (c - '0');
	//return n; }
	return minus ? -n : n; }
si void scan(char *s) {while (!isspace(*s++ = gcu()));}
#define pcu putchar_unlocked
#define svo si void out
template <typename T>
svo(T n) {
	static char buf[20];
	char *p = buf;
	//if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
svo(const char *s){while(*s)pcu(*s++);}
svo(char *s){while(*s)pcu(*s++);}
svo(char c){pcu(c);}
template <typename T>
//svo(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
svo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
template <typename head, typename... tail>
svo(head&& h, tail&&... t){out(h);out(move(t)...);}
#undef svo
#undef si

#define v vector
struct graph {
	struct node {int n, w;};
	v<v<node>> nodes;

	void read(int n) {
		nodes.resize(n);
		for (auto &x: nodes) {
			in();
			for (int k = in(); k--;) {
				int c = in();
				x.push_back({c, in()});
			}
		}
	}

	v<node> dks() {
		v<node> w(nodes.size(), {0, INT_MAX});
		w[0].w = 0;
		priority_queue<node> q;
		q.push({0, 0});
		while (!q.empty()) {
			node n = q.top();
			q.pop();
			for (node &x: nodes[n.n]) {
				w[x.n].w = min(w[x.n].w, n.w + x.w);
				if (!w[n.n].n)
					q.push({x.n, w[x.n].w});
			}
			w[n.n].n = 1;
		}
		return move(w);
	}
};

bool operator < (const graph::node &a, const graph::node &b) {
	return a.w > b.w;
}

int main() {
	graph g;
	g.read(in());
	int i = 0;
	for (auto &x: g.dks())
		out(i++, ' ', x.w, '\n');
}

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