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 <sstream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>

#define LP(i,n) for(int i=0;i<n;i++)
#define Mset(x,v) memset(x,v,sizeof(x))

using namespace std;
using LL=long long;

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>
#include <vector>
#include <queue>
using namespace std;
typedef vector <int> vi;
typedef vector <vi> vvi;

class blanch{
	public:
		int weight;
		int total;
		int from;
		int to;
		blanch():
			weight(0), from(0), to(0){};
		blanch(int newweight, int newfrom, int newto):
			weight(newweight), from(newfrom), to(newto){};
};
typedef vector <blanch> vb;


bool operator<( const blanch &blanch1, const blanch &blanch2){
	return (blanch1.weight > blanch2.weight);
	}

bool operator>( const blanch &blanch1, const blanch &blanch2){
	return (blanch1.weight < blanch2.weight);
	}

int make_graph(vvi &graph, vi &stamp){
	int n=graph.size();
	for (int i=0; i<n; i++){
		for (int j=0; j<n; j++){
			graph[i][j]=0;
		}
	}

	for (int j=0; j<n; j++){
		int i2,n2;
		cin>>i2;
		cin>>n2;
		for (int i=0; i<n2; i++){
			int j2;
			cin>>j2;
			cin>>graph[i2][j2];
		}
		stamp[i2] = -1;
	}
	return 0;
}

int Shortest_Path(vvi &graph, vi &stamp){

	priority_queue<blanch, vb, less<vb::value_type> > pq;
	int n = graph.size(), p1=0;
	stamp[p1] = 0;

	while (p1!=-1){
		for (int p2=0; p2<n; p2++){
			int *tmp = &graph[p1][p2];
			if (*tmp!=0 && stamp[p2]==-1){
				pq.push(blanch(*tmp+stamp[p1], p1, p2));
			}
		}
		p1 = -1;
		while (! pq.empty()){
			blanch tmp = pq.top();
			if (stamp[tmp.from]!=-1 && stamp[tmp.to]==-1){
				p1 = tmp.to;
				stamp[p1] = tmp.weight;
				pq.pop();
				break;
			} else
				pq.pop();
		}
	}
	return 0;
}

int resultout(vi &stamp){
	int n = stamp.size();
	for (int i=0; i<n; i++){
		cout<<i<<" "<<stamp[i]<<endl;
	}
	return 0;
}

int main(void){

	int n;
	cin>>n;
	vvi G(n, vi(n));
	vi stamp(n);

	make_graph(G, stamp);

	Shortest_Path(G, stamp);

	resultout(stamp);

	return 0;
}

C++: #include <iostream>
using namespace std;
static const int SIZE = 100;
static const int INF = 1e9+7;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int NIL = -1;

int n;
int G[SIZE][SIZE],d[SIZE];

void dijkstra(){
    int u,mincost;
    int color[SIZE];

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

    d[0] = 0;
    color[0] = GRAY;

    while(1){
        mincost = INF;
        u = NIL;

        for(int i=0; i<n; i++){
            if(color[i] != BLACK && d[i] < mincost){
                mincost = d[i];
                u = i;
            }
        }

        if(u == NIL) break;

        color[u] = BLACK;

        for(int v=0; v<n; v++){
            if(color[v] != BLACK && G[u][v] != INF){
                if(G[u][v] + d[u] < d[v]){
                    d[v] = G[u][v] + d[u];
                    color[v] = GRAY;
                }
            }
        }
    }
}

int main(){
    cin>>n;

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            G[i][j] = INF;
        }
    }

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

    dijkstra();

    for(int i=0; i<n; i++){
        cout<<i<<" ";
        if(d[i] != INF) cout<<d[i]<<endl;
        else cout<<-1<<endl;
    }

    return 0;
}