Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const INF = 1 << 60

type Edge struct {
	to, cost int
}

type Node struct {
	id, cost int
}

type PQ []Node

func (pq PQ) Len() int           { return len(pq) }
func (pq PQ) Less(i, j int) bool { return pq[i].cost < pq[j].cost }
func (pq PQ) Swap(i, j int)      { pq[i], pq[j] = pq[j], pq[i] }

func (pq *PQ) Push(x interface{}) {
	*pq = append(*pq, x.(Node))
}

func (pq *PQ) Pop() interface{} {
	old := *pq
	n := len(old)
	x := old[n-1]
	*pq = old[0 : n-1]
	return x
}

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	E := make([][]Edge, N)
	for i := 0; i < N; i++ {
		id, k := sc.nextInt(), sc.nextInt()
		E[id] = make([]Edge, k)
		for j := 0; j < k; j++ {
			to, cost := sc.nextInt(), sc.nextInt()
			E[id][j] = Edge{to, cost}
		}
	}

	d := make([]int, N)
	for i := 0; i < N; i++ {
		d[i] = INF
	}
	done := make([]bool, N)
	pq := &PQ{}
	heap.Init(pq)
	d[0] = 0
	heap.Push(pq, Node{0, 0})
	for pq.Len() > 0 {
		cur := heap.Pop(pq).(Node).id
		if done[cur] {
			continue
		}
		done[cur] = true
		for i := 0; i < len(E[cur]); i++ {
			to, cost := E[cur][i].to, E[cur][i].cost+d[cur]
			if !done[to] && cost < d[to] {
				d[to] = cost
				heap.Push(pq, Node{to, cost})
			}
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprintln(wtr, i, d[i])
	}
	wtr.Flush()
}

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

class blanch{
	public:
		bool visited;
		int distance;
		int from;
		int to;
};
typedef vector <blanch> vb;
typedef vector <vb> vvb;

int make_graph(vvb &graph, vb &nodes){

	int n=nodes.size();
	for (int i=0; i<n; i++){
		nodes[i].visited = false;
		nodes[i].distance = INT_MAX;
	}

	for (int i=0; i<n; i++){
		int i2, n2;
		cin>>i2;
		cin>>n2;

		blanch tmp;
		tmp.visited = false;
		tmp.from = i2;

		for (int j=0; j<n2; j++){
			cin>>tmp.to;
			cin>>tmp.distance;
			graph[i2].push_back(tmp);
		}
	}
	return 0;
}

int Shortest_Path(vvb &graph, vb &nodes){

	int p1=0;
	nodes[p1].distance = 0;

	int p2;
	while (p1 != -1){
		nodes[p1].visited=true;
		for (int i = 0; i < (int)graph[p1].size(); i++){
			blanch tmp = graph[p1][i];
			p2=tmp.to;
			if (!nodes[p2].visited){
				int tmp2 = tmp.distance + nodes[p1].distance;
				if (tmp2 < nodes[p2].distance){
					tmp.distance = tmp2;
					nodes[p2] = tmp;
				}
			}
		}

		p1 = -1;
		int tmp = INT_MAX;
		for (int i=0; i<(int)graph.size(); i++){
			if (!nodes[i].visited && nodes[i].distance<tmp){
				p1 = i;
				tmp = nodes[i].distance;
			}
		}
	}
	return 0;
}

int resultout(vb &nodes){
	for (int i=0; i<(int)nodes.size(); i++){
		cout<<i<<" "<<nodes[i].distance<<endl;
	}
	return 0;
}

int main(void){

	int n;
	cin>>n;
	vvb G(n, vb());
	vb nodes(n);

	make_graph(G, nodes);

	Shortest_Path(G, nodes);

	resultout(nodes);
	G.clear();
	nodes.clear();

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define RREP1(x,n) for(int x = n-1; x >= 0; x--)
#define RREP2(x,s,e) for(int x = s; x >= e; x--)
#define BR printf("\n")
#define INF 2000000000
#define INF_LL 9223372036854775806

typedef long long ll;

int G;

ll length[10000];

class edge{
public:
    int fromid;
    int toid;
    int m;
    int len;
    
    edge(int from){
        len = 0;
        fromid = from;
        INPUT(toid);
        INPUT(m);
    }
    
    bool operator < (const edge &e) const {
        return len < e.len;
    }
};

//??§?????????????????????????????????????????§??????????????\?????????
priority_queue<edge> PQ;
vector<vector<edge> > eList;

void dijkstra(int i, ll len){
    if(length[i] != INF_LL) return;
    
    //1.??????????????¢????¢????
    PQ.pop();
    length[i] = len;
    
    //2.?¨??????????????£????????´?
    REP1(k,eList[i].size()){
        if(length[i] != INF_LL){
            eList[i][k].len = -length[i] - eList[i][k].m;
            PQ.push(eList[i][k]);
        }
    }
    
    //3.?¬?????¨??????????????¢?????????????
    while (PQ.size() != 0 && length[PQ.top().toid] != INF_LL) {
        PQ.pop();
    }
    
    //4.?????£????????????
    if (PQ.size() != 0) {
        dijkstra(PQ.top().toid, -PQ.top().len);
    }
}

int main(){
    INPUT(G);
    REP1(i,G){
        vector<edge> list;
        eList.push_back(list);
        length[i] = INF_LL;
        INT(from);
        INT(k);
        REP1(j,k){
            edge e(from);
            eList[i].push_back(e);
        }
    }
    PQ.push(eList[0][0]);
    
    dijkstra(0,0);
    
    REP1(i,G){
        printf("%d %lld\n",i,length[i]);
    }
    
    return 0;
}

C++: #include <stdio.h>
#include <vector>

using namespace std;

struct Info{
	Info(int arg_weight,short arg_to){
		weight = arg_weight;
		to = arg_to;
	}
	int weight;
	short to;
};


int main(){
	int n,count=0,t,min,min_index,tmp,left_node,right_node,dist,t_to_i;
	scanf("%d",&n);
	vector<Info> V[n];

	int P[n],zero_dist[n];

	for(int i=0;i<n;i++){
		P[i]=0;
		zero_dist[i] = 10000001;
	}
	zero_dist[0] = 0;
	P[0]=1;

	for(int i=0;i<n;i++){
		scanf("%d %d",&left_node,&tmp);
		if(left_node == 0){
			for(int k=0;k<tmp;k++){
				scanf("%d %d",&right_node,&dist);
				zero_dist[right_node] = dist;
			}
		}else{
			for(int k=0;k<tmp;k++){
				scanf("%d %d",&right_node,&dist);
				V[left_node].push_back(Info(dist,right_node));
			}
		}
	}

	while(count<n-1){

		min=10000001;
		for(int i=1;i<n;i++){
			if(P[i]==0&&zero_dist[i]<min){
				min_index = i;
				min = zero_dist[i];
			}
		}
		t = min_index;
		P[t]=1;
		count++;

		for(int i=1;i<n;i++){
			t_to_i = 10000001;
			for(int k=0;k<V[t].size();k++){
				if(V[t][k].to == i){
					t_to_i = V[t][k].weight;
					break;
				}
			}
			if(zero_dist[i] > zero_dist[t]+t_to_i){
				zero_dist[i]=zero_dist[t]+t_to_i;
			}
		}
	}

	for(int i=0;i<n;i++){
		printf("%d %d\n",i,zero_dist[i]);
	}

    return 0;
}