Go: package main

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

const MAX = 100
const INFTY = math.MaxInt64
const WHITE = 0
const GRAY = 1
const BLACK = 2

var n int
var M [MAX][MAX]int

func dijkstra() {
	var minv int
	var d [MAX]int
	var color [MAX]int

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

	d[0] = 0
	color[0] = GRAY
	for {

		minv = INFTY
		u := -1
		for 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 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 i := 0; i < n; i++ {
		fmt.Printf("%v %v\n", i, d[i])
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ = strconv.Atoi(sc.Text())

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			M[i][j] = INFTY
		}
	}

	for i := 0; i < n; i++ {
		sc.Scan()
		f, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			sc.Scan()
			c, _ := strconv.Atoi(sc.Text())
			M[f][v] = c
		}
	}
	dijkstra()
}

C++: #include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define PRINTD(n) printf("%d\n",n)
#define DEBUG printf("%s\n","debug")
using namespace std;
//////////////////////////////////////////////////////
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_12_B&lang=jp
struct Vertex {
	// edge information
	vector<int> edges_to; //to vertex number
	vector<int> edges_cost; // edge cost
	
	//for dijkstra
	bool done; //conform or not
	int cost; // now cost
	
	bool operator<(const Vertex& another) const { // priority --> min
        return another.cost < cost; // order(cost)
    }
	
	bool operator==(const Vertex& another) const {
        return another.cost == cost; // order(cost)
    }
};

const int V_MAX = 10003;
struct Vertex v[V_MAX];


int main(){
	priority_queue<Vertex>Q;
	int n; // vertex 0-indexed
	SCD(n);
	REP(i,n){ // 0-indexed
		int u,k;
		SCD2(u,k);
		REP(j,k){
			int nv,c; // to edge , its cost
			SCD2(nv,c);
			v[u].edges_to.push_back(nv);
			v[u].edges_cost.push_back(c);
		}
	}
	
	REP(i,n){
		v[i].done = false;
		v[i].cost = -1;
	}
	
	v[0].cost = 0; //start
	Q.push(v[0]);
	
	while (!Q.empty()){
		Vertex nowV = Q.top(); Q.pop();
		nowV.done = true;
		
		REP(i,nowV.edges_to.size()){
			int nto = nowV.edges_to[i];
			int ncost = nowV.cost + nowV.edges_cost[i];
			if (((v[nto].cost) < 0) or (ncost < v[nto].cost)){  //not visited or required refresh
				v[nto].cost = ncost;
				Q.push(v[nto]);
			
			}
			
		}
	}
	
	REP(i,n){ // output
		printf("%d %d\n",i,v[i].cost);
	}
	
	
}

C++: #include<bits/stdc++.h>
using namespace std;
#define ll long long 

	
const int INF = 7+(1e+9);
typedef int Weight;
struct Edge {  //src:辺の始点,dst:辺の終点,weight:辺の重さ
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : //辺は重さが重いものを"小さい"と定義する
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

//引数 g:隣接リスト,s:始点,dist:各頂点までの距離が入る,prev:最短路木の親頂点が入る
//戻値 なし
void shortestPath(const Graph &g,int s,vector<Weight> &dist,vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q;
  Q.push(Edge(-2, s, 0));
  while(!Q.empty()) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    for(auto f=g[e.dst].begin();f!=g[e.dst].end();f++){
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}
 


int main(){
  int v; cin >> v;
  Graph g(v);    //頂点数vの空隣接リストgを生成
  for(int i=0;i<v;i++){
        int u,k; cin >>u >>k;
        for(int j=0;j<k;j++){
            int vv,cc; cin >>vv >>cc;
            g[u].push_back(Edge(u,vv,cc));    //隣接リストgにsからtに向かう重さwの辺を追加
        }
  }
  vector<Weight> dist;
  vector<int> prev;
  shortestPath(g,0,dist,prev);
  for(int i=0;i<v;i++){
        cout<<i<<" "<<dist[i]<<endl;
  }
  
}

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;

}