Go: package main

import (
	"bufio"
	"fmt"
	"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() {
	sc := bufio.NewScanner(os.Stdin)
	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{1}, shortestList, adjacentMatrix)
	for _, v := range shortestList {
		fmt.Printf("%d %d\n", v.getEnd()-1, v.shortest)
	}
}

func (si ShortestInfo) getEnd() int {
	if len(si.edges) == 0 {
		return 1
	} 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-1]
}

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-1] = shortestInfo
}

func findAdjacents(currentNode int, adjacentMatrix [][]int) []Edge {
	adjacents := adjacentMatrix[currentNode-1]
	edges := []Edge{}
	for i, v := range adjacents {
		if v > 0 {
			edges = append(edges, Edge{start: currentNode, end: i + 1, 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;

vector<pair<int, int>> adja[10000];

#define INF (1 << 30)

int main() {
	int n, id, k, a, b;

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> id >> k;
		for (int j = 0; j < k; ++j) {
			cin >> a >> b;
			adja[id].push_back(make_pair(a, b));
		}
	}

	priority_queue<pair<int, int>> que;
	que.push(make_pair(0, 0)); //cost, node
	int cost[10000];
	fill(cost, cost + n, INF);

	while (!que.empty()) {
		for (int i = 0, size = que.size(); i < size; ++i) {
			pair<int, int> top = que.top();
			que.pop();

			if (cost[top.second] < top.first) {
				continue;
			}
			cost[top.second] = top.first;

			for (int j = 0, len = adja[top.second].size(); j < len; ++j) {
				que.push(make_pair(top.first + adja[top.second][j].second, adja[top.second][j].first));
			}
		}
	}

	for (int i = 0; i < n; ++i) {
		cout << i << " " << cost[i] << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
int n,H[100][100];
void dd()
{
    int minv;
    int d[100],c[100];
    for(int i=0;i<n;i++)
    d[i]=INFTY;
    d[0]=0;
    while(1)
    {
        minv=INFTY;
        int u=-1;
        for(int i=0;i<n;i++)
        {
            if(minv>d[i]&&c[i]!=BLACK)
            {
                u=i;
                minv=d[i];
            }
        }
        if(u==-1) break;
        c[u]=BLACK;
        for(int v=0;v<n;v++)
        {
            if(c[v]!=BLACK&&H[u][v]!=INFTY)
            {
                if(d[v]>d[u]+H[u][v])
                {
                    d[v]=d[u]+H[u][v];
                    c[v]=GRAY;
                }
            }
        }
    }
    for(int i=0;i<n;i++)
            printf("%d %d\n",i,(d[i]==INFTY?-1:d[i]));
}
int main()
{
    int a,b,c,d;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
        H[i][j]=INFTY;
    for(int i=0;i<n;i++)
    {
        scanf("%d %d",&a,&b);
        for(int j=0;j<b;j++)
        {
            scanf("%d %d",&c,&d);
            H[a][c]=d;
        }
    }
    dd();
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
static const int MAX=10000;
static const int INFTY=2000000000;

vector<pair<int,int> > A[MAX];
int dk[MAX],H[MAX+1],tail,where[MAX];

void cminHeap(int i){
    int left,right,least;
    left=2*i;right=left+1;least=i;
    if(left<=tail&&dk[H[left]]<dk[H[i]])least=left;
    if(right<=tail&&dk[H[right]]<dk[H[least]])least=right;
    if(i==least)return;
    swap(H[i],H[least]);swap(where[H[i]],where[H[least]]);
    cminHeap(least);
}

void pminHeap(int i){
    int parent=i/2;
    if(parent==0||dk[H[parent]]<=dk[H[i]])return;
    swap(H[parent],H[i]);swap(where[H[parent]],where[H[i]]);
    pminHeap(parent);
}

void heap_update(int u){
    int x=H[u];
    cminHeap(u);
    if(H[u]==x)pminHeap(u);
}

void SSSP(int n){
    for(int i=0;i<n;i++){
        dk[i]=INFTY;
        H[i+1]=i;
        where[i]=i+1;
    }
    dk[0]=0;
    tail=n;
    int v;
    while(tail>0){
        v=H[1];H[1]=H[tail];where[H[tail]]=1;
        tail--;where[v]=-1;
        cminHeap(1);
        vector<pair<int,int> >::iterator it;
        for(it=A[v].begin();it<A[v].end();it++){
            pair<int,int> item=*it;
            if(where[item.first]!=-1){
                if(dk[item.first]>dk[v]+item.second){
                    dk[item.first]=dk[v]+item.second;
                    heap_update(where[item.first]);
                }
            }
        }
    }
}

int main(){
    int n,v,k,u,d;
    cin>>n;
    for(int i=0;i<n;i++){
        scanf("%d %d",&v,&k);
        for(int j=0;j<k;j++){
            scanf("%d %d",&u,&d);
            A[v].push_back(make_pair(u,d));
        }
    }
    SSSP(n);
    for(int i=0;i<n;i++)printf("%d %d\n",i,dk[i]);
}