Go: package main

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

const (
	MAX_N      = 10000
	MAX_WEIGHT = 100000
)

type Edge struct {
	start  int
	end    int
	weight int
}

type ShortestInfo struct {
	edges    []Edge
	shortest int
}

func main() {
	doMain(os.Stdin)
}

func doMain(reader io.Reader) {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	shortestList := make([]ShortestInfo, n)
	for i := 1; i < n; i++ {
		shortestList[i] = ShortestInfo{edges: []Edge{}, shortest: MAX_N*MAX_WEIGHT + 1}
	}

	adjacentMatrix, err := createAdjacentMatrix(n, sc)
	if err != nil {
		panic(err)
	}

	sssp([]int{0}, shortestList, adjacentMatrix)
	for _, v := range shortestList {
		fmt.Println(v.getEnd(), v.shortest)
	}
}

func (si ShortestInfo) getEnd() int {
	if len(si.edges) == 0 {
		return 0
	} else {
		return si.edges[len(si.edges)-1].end
	}
}

func createAdjacentMatrix(n int, sc *bufio.Scanner) ([][]int, error) {
	adjacentMatrix := make([][]int, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		adjacentMatrix[id] = make([]int, n)
		for j := 0; j < n; j++ {
			adjacentMatrix[id][j] = -1
		}
		vertexNum, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		for j := 0; j < vertexNum; j++ {
			v, err := nextInt(sc)
			if err != nil {
				return nil, err
			}
			c, err := nextInt(sc)
			if err != nil {
				return nil, err
			}
			adjacentMatrix[id][v] = c
		}
	}
	return adjacentMatrix, nil
}

func sssp(nodeStack []int, shortestList []ShortestInfo, adjacentMatrix [][]int) {
	for len(nodeStack) > 0 {
		currentNode := nodeStack[0]
		nodeStack = nodeStack[1:]
		currentShortest := getShortest(currentNode, shortestList)
		adjacents := findAdjacents(currentNode, adjacentMatrix)
		for i := 0; i < len(adjacents); i++ {
			adj := adjacents[i]
			if currentShortest.shortest+adj.weight < getShortest(adj.end, shortestList).shortest {
				setShortest(adj.end, adj, currentShortest, shortestList)
				nodeStack = append(nodeStack, adj.end)
			}
		}
	}
}

func getShortest(node int, shortestList []ShortestInfo) ShortestInfo {
	return shortestList[node]
}

func setShortest(node int, edge Edge, currentShortest ShortestInfo, shortestList []ShortestInfo) {
	newEdges := make([]Edge, len(currentShortest.edges)+1)
	for i := 0; i < len(newEdges)-1; i++ {
		newEdges[i] = currentShortest.edges[i]
	}
	newEdges[len(newEdges)-1] = edge
	shortestInfo := ShortestInfo{edges: newEdges, shortest: currentShortest.shortest + edge.weight}
	shortestList[node] = shortestInfo
}

func findAdjacents(currentNode int, adjacentMatrix [][]int) []Edge {
	adjacents := adjacentMatrix[currentNode]
	edges := []Edge{}
	for i, v := range adjacents {
		if v >= 0 {
			edges = append(edges, Edge{start: currentNode, end: i, weight: v})
		}
	}
	return edges
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
string u="abcdefghijklmnopqrstuvwxyz";

struct edge {int to;LL cost;};

const int M_N=10000;

vector<edge> G[M_N+1];
LL d[M_N+1];

struct Dijkstra{

    void dijkstra(int s){
        priority_queue<P,vector<P>,greater<P>> que;
        que.push(P(0,s));
        while(!que.empty()){
            P p=que.top();
            que.pop();
            int v=p.second;
            if(d[v]<p.first) continue;
            for(int i=0;i<G[v].size();i++){
                edge e=G[v][i];
                if(d[e.to]>d[v]+e.cost){
                    d[e.to]=d[v]+e.cost;
                    que.push(P(d[e.to],e.to));
                }
            }
        }
    }

};

int main(){
    Dijkstra Ds;
    fill(d,d+M_N+1,LINF);
    d[0]=0;
    int N;
    cin >> N;
    int u,k,v,c;
    while(cin >> u >> k){
        for(int i=0;i<k;i++){
            cin >> v >> c;
            G[u].push_back({v,c});
        }
    }
    Ds.dijkstra(0);
    for(int i=0;i<N;i++){
        cout << i <<" "<< d[i] << endl;
    }
    return 0;
}

C++: #include<stdio.h>
using namespace std;
const int maxn=1<<21;
int n;
int a[1000000][1000000];
void dan()
{
    int minx;
    int d[105],color[105];
    for(int i=0;i<n;i++)
    {
        d[i]=maxn;
        color[i]=0;
    }
    d[0]=0;
    while(1)
    {
        minx=maxn;
        int u=-1;
        for(int i=0;i<n;i++)
        {
            if(d[i]<minx&&color[i]!=1)
            {
                minx=d[i];
                u=i;
            }
        }
        if(u==-1) break;
        color[u]=1;
        for(int i=0;i<n;i++)
        {
            if(color[i]==1||a[u][i]==maxn) continue;
            if(d[i]>d[u]+a[u][i])
            {
                d[i]=d[u]+a[u][i];

            }
        }
    }
    for(int i=0;i<n;i++)
    {
        printf("%d ",i);
        printf("%d\n",(d[i]==maxn)?-1:d[i]);
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<105;i++)
    {
        for(int j=0;j<105;j++)
        {
            a[i][j]=maxn;
        }
    }
    int k,c,u,v;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&k,&c);
        for(int j=0;j<c;j++)
        {
            scanf("%d%d",&u,&v);
            a[k][u]=v;
        }
    }
    dan();
    return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
const int max_v = 10100;
const int max_e = 505000;
const int inf = 0x3fffffff;

typedef pair<int, int> P;

typedef struct edge {
    int to, dist;
    edge():to(0),dist(0) {}
    edge(int _to, int _dist):to(_to),dist(_dist) {}
    bool operator < (const edge & o) const {
	return dist > o.dist;
    }
}edge;

struct graph {
    int V, E;
    int d[max_v], prev[max_v];
    bool vis[max_v];
    vector<edge> G[max_v];
    graph():V(0),E(0) {}

    graph(int _V):V(_V),E(0) {}

    graph(int _V, int _E, int ed[][3], bool bidirect):V(_V),E(_E) {
	rep(i, E) {
	    int u = ed[i][0], v = ed[i][1], dist = ed[i][2];
	    G[u].push_back(edge(v, dist));
	    if (bidirect) G[v].push_back(edge(v, dist));
	}
    }
    graph(int _V, int g[][max_v]) {
	V = _V; E = 0;
	rep(i, V) rep(j, V)
	    if (g[i][j] != inf) {
		G[i].push_back(edge(j, g[i][j]));
		++E;
	    }
    }

    void add_edge(int u, int v, int c) {
	G[u].push_back(edge(v, c));
    }

    void output() {
	rep(i, V) {
	    printf("[%d] ", i);
	    rep(j, G[i].size()) {
		printf("(%d %d) ", G[i][j].to, G[i][j].dist);
	    }
	    putchar('\n');
	}
    }

    void dijkstra(int g[][max_v], int s) {
	rep(i, V) d[i] = inf;
	rep(i, V) prev[i] = -1;
	rep(i, V) vis[i] = false;

	d[s] = 0;
	rep(i, V) {
	    int tmp = inf;
	    int u = -1;
	    rep(j, V) {
		if(!vis[j] && d[j] < tmp) {
		    tmp = d[j];
		    u = j;
		}
	    }
	    vis[u] = true;
	    rep(j, V) {
		if(!vis[j] && d[u] + g[u][j] < d[j]) {
		    d[j] = d[u] + g[u][j];
		    prev[j] = u;
		}
	    }
	}
    }

    void dijkstra(int s) {
	rep(i, V) d[i] = inf;
	rep(i, V) prev[i] = -1;
	rep(i, V) vis[i] = false;
	
	priority_queue<edge> pq;
	pq.push(edge(s, 0));
	d[s] = 0;

	while(! pq.empty()) {
	    edge e = pq.top(); pq.pop();
	    if(e.dist > d[e.to]) continue;
	    d[e.to] = e.dist;
	    vis[e.to] = true;
	    
	    rep(j, G[e.to].size()) {
		int v = G[e.to][j].to;
		int dist = G[e.to][j].dist;

		if(!vis[v] && d[e.to] + dist < d[v]) {
		    d[v] = d[e.to] + dist;
		    prev[v] = e.to;
		    pq.push(edge(v, d[v]));
		}
	    }
	}
    }
};

int N, M;

void solve() {
    int u, k, v, c;
    scanf("%d", &N);
    graph g = graph(N);
    rep(i, N) {
	scanf("%d%d", &u, &k);
	rep(j, k) {
	    scanf("%d%d", &v, &c);
	    g.add_edge(u, v, c);
	}
    }
    g.dijkstra(0);
    rep(i, N) {
	printf("%d %d\n", i, g.d[i]);
    }
}

int main() {
    solve();
    return 0;
}