Go: package main

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

const (
	MAX_N      = 100
	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;
#define MAX_V 100
#define INF (1 << 21)

int cost[MAX_V][MAX_V];
int d[MAX_V];
bool used[MAX_V];
int V;

int s = 0; // start

void dijkstra()
{
    for (int i = 0; i < V; i++) {
        d[i] = INF;
        used[i] = false;
    }

    d[s] = 0;
    for(;;) {
        int v = -1;
        for (int u = 0; u < V; u++) {
            if (!used[u] && (v == -1 || d[u] < d[v]))
                v = u;
        }
        if (v == -1) break;

        used[v] = true;

        for (int u = 0; u < V; u++) {
            d[u] = min(d[u], d[v] + cost[v][u]);
        }
    }

    for (int u = 0; u < V; u++) {
        cout << u << " " << (d[u] == INF ? -1 : d[u]) << endl;
    }

}
int main()
{
    cin >> V;

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

    dijkstra();

    return 0;
}

C++: 
#include <iostream>
using namespace std;
#define INFTY  (1 << 30)
const int Total = 101;
const int White = 0;//未访问
const int Grey = 1;//访问中
const int Black = 2;//不再访问
int  totalnode,Matrix[Total][Total], Color[Total], DistanceBetweenRootAndNode[Total],Parent[Total];
void includeBuildSingleSourceShortestPath()
{
	int minimumdistance, min;
	DistanceBetweenRootAndNode[0] = 0;//默认以0为根
	Parent[0] = -1;
	Color[0] = Grey;
	while (1)
	{
		minimumdistance = INFTY;
		for (int i = 0; i < totalnode; i++)
		{
			if (Color[i] != Black && DistanceBetweenRootAndNode[i] < minimumdistance)//在未访问或访问的点中找出最短的那个
				minimumdistance = DistanceBetweenRootAndNode[i], min = i;
		}
		if (minimumdistance == INFTY)break;//全部为黑色
		Color[min] = Black;//以min为基础搜相连的结点
		for (int i = 0; i < totalnode; i++)
		{
			if (Matrix[min][i] != 0 && Color[i] != Black)//找出相连且未被设为不再访问的结点
			{
				if (DistanceBetweenRootAndNode[min] + Matrix[min][i] < DistanceBetweenRootAndNode[i])
					//若根到点min的距离 加上 点min到点i的距离 小于 之前根到点i的距离
				{
					DistanceBetweenRootAndNode[i] = DistanceBetweenRootAndNode[min] + Matrix[min][i];
					Parent[i] = min;
					Color[i] = Grey;
				}

			}

		}


	}
}
int main()
{
	int frontnode,backnode,degree,distancebetweenfrontnodeandbacknode;
	cin >> totalnode;
	for (int i = 0; i < totalnode; i++)DistanceBetweenRootAndNode[i] = INFTY;//初始化距离
	for (int i = 0; i < totalnode; i++)Color[i] = White;
	for (int i = 0; i < totalnode; i++)
		for (int j = 0; j < totalnode; j++)
			Matrix[i][j] = 0;
	for (int i = 0; i < totalnode; i++)//有向图
	{
		cin >>frontnode>>degree;//frontnode中题目其实就默认从0开始
		for (int j = 0; j < degree; j++)
		{
			cin >> backnode>> distancebetweenfrontnodeandbacknode;
			Matrix[frontnode][backnode] = distancebetweenfrontnodeandbacknode;
		}
	}
	includeBuildSingleSourceShortestPath();
	for (int i = 0; i < totalnode; i++)
		cout << i <<" "<< DistanceBetweenRootAndNode[i]<<endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,i,j;
    cin>>n;
    vector<bool> used(n,false);
    vector<int> dist(n,99999999);
    map<int,vector<pair<int,int>>> v;
    for(i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        for(j=0;j<b;j++){
            int to,cost;
            cin>>to>>cost;
            v[i].emplace_back(to,cost);
        }
    }
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
    q.push(make_pair(0,0));
    dist[0]=0;
    while(!q.empty()){
        pair<int,int> e;
        e=q.top();q.pop();
        used[e.second]=true;
        dist[e.second]=min(dist[e.second],e.first);
        for(auto p:v[e.second]){
            if(!used[p.first]){
                q.push(make_pair(dist[e.second]+p.second,p.first));
            }
        }
    }
    for(i=0;i<n;i++){
        cout<<i<<' '<<dist[i]<<endl;
    }
}

C++: #include <bits/stdc++.h>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

map<ll, ll> d;
priority_queue< Pll, vector<Pll>, greater<Pll> > que;
map<ll, vector<Pll> > edges;

void dijkstra(ll start){
    d[start] = 0;
    que.push(Pll(0, start));

    while(!que.empty()){
        Pll v = que.top(); que.pop();
        if(d.find(v.second) != d.end() && d[v.second] < v.first) continue;
        for(Pll e: edges[v.second]){
            if(d.find(e.first) == d.end() || d[e.first] > d[v.second] + e.second){
                d[e.first] = d[v.second] + e.second;
                que.push(Pll(d[e.first], e.first));
            }
        }
    }
}

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n;
    ll u, k, c, v;
    cin >> n;
    rep(n){
        cin >> u >> k;
        repp(j, k){
            cin >> v >> c;
            edges[u].emplace_back(v, c);
        }
    }

    dijkstra(0);
    repp(u, n) cout << u << " " << d[u] << endl;

}