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{0}, shortestList, adjacentMatrix)
	for _, v := range shortestList {
		fmt.Printf("%d %d\n", 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 <iostream>
#include <vector>
#include <queue>

using ll = long long;
using namespace std;
/* initialize */
int n;
vector<pair<int, int> > adj[10000];

void dijkstra(){
    priority_queue<pair<int,int> > PQ;
    int color[10000];
    int d[10000];
    for (int i = 0; i < n; ++i) {d[i] = INT32_MAX; color[i] = 0;};
    d[0] = 0;
    PQ.push(make_pair(0, 0));
    color[0] = 1;
    while (!PQ.empty()){
        pair<int, int> f = PQ.top(); PQ.pop();
        int u = f.second;
        color[u] = 2;
        if (d[u] < f.first * (-1)) continue;

        for (int j = 0; j < adj[u].size(); ++j) {
            int v = adj[u][j].first;
            if(color[v] == 2) continue;
            if (d[v] > d[u] + adj[u][j].second){
                d[v] = d[u] + adj[u][j].second;
                PQ.push(make_pair(d[v]*-1, v));
                color[v] = 1;
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << i << " " << (d[i] == INT32_MAX ? -1 : d[i]) << "\n";
    }
};
/* main */
int main() {
    int k, u, v, c;

    cin >> n;
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; ++j) {
            scanf("%d %d", &v, &c);
            adj[u].emplace_back(v,c);
        }
    }
    dijkstra();
    return 0;
}

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

using namespace std;
#define MAX_N (10010)
#define INF (1000000100)
typedef struct {
    int to;
    int w;
} Edge;

vector<Edge> G[MAX_N];
int n;

int dist[MAX_N];
bool arrived[MAX_N];

void dijkstra(int s)
{
    priority_queue< pair<int, int> > PQ;
    for ( int i = 0; i < n; i++ ) {
	dist[i] = INF;
	arrived[i] = false;
    }

    dist[s] = 0;
    PQ.push(make_pair(0, 0));

    while ( !PQ.empty() ) {
	pair<int, int> u = PQ.top(); PQ.pop();
	if ( u.second > dist[u.first] ) continue;
	arrived[u.first] = true;
	
	for ( int i = 0; i < G[u.first].size(); i++ ) {
	    Edge e = G[u.first][i];
	    if ( !arrived[e.to] && dist[e.to] > (dist[u.first] + e.w) ) {
		dist[e.to] = dist[u.first] + e.w;
		PQ.push(make_pair(e.to, dist[e.to]));
	    }
	}
    }

}

int main()
{
    scanf("%d", &n);
    
    for ( int i = 0; i < n; i++ ) {
	int u, k;
	scanf("%d %d", &u, &k);

	for ( int j = 0; j < k; j++ ) {
	    int v, c;
	    Edge e;
	    scanf("%d %d", &v, &c);
	    e.to = v;
	    e.w = c;
	    G[u].push_back(e);
	}
    }

    dijkstra(0);

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

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>

#define INF 1000000000
using namespace std;

struct edge {
    int from;
    int to;
    int w;
};
struct node {
    node() : id {-1}, d {INF}, ns {} {};
    node(int i, vector<edge>& vec) : id {i}, d {INF}, ns {vec} {};
    int id;
    int d;
    vector<edge> ns;
};

struct node_s {
    int id;
    int d;
};

vector<int> dijkstra(node* graph, int n, int st){
    auto ds = vector<int>(n, INF);
    auto comp = [](node_s* x, node_s* y){return x->d > y->d;};
    priority_queue<node_s*, vector<node_s*>, decltype(comp)> que(comp);
    node_s* start = new node_s {graph[st].id, 0};
    que.push(start);
    while(que.size()){
        node_s* n = que.top();
    /    cout << n->id << ' ' << n->d << endl;
        que.pop();
        if(n->d < ds[n->id]){
            ds[n->id] = n->d;
            for(auto e : graph[n->id].ns){
                if(ds[e.to] < INF){
                    continue;
                }
                node_s* next_n = new node_s {graph[e.to].id, ds[n->id] + e.w};
                que.push(next_n);
            }
        }
        delete n;
    }
    return ds;
}

int main(){
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    int n;
    cin >> n;
    node graph[n];
    for(int i = 0; i < n; ++i){
        int id;
        int m;
        cin >> id >> m;
        auto vec = vector<edge>(m);
        int v, c;
        for(int j = 0; j < m; ++j){
            cin >> v >> c;
            vec[j] = edge {id, v, c};
        }
        graph[id] = node(id, vec);
    }
    auto ds = dijkstra(graph, n, 0);
    for(int i = 0; i < n; ++i){
        cout << i << ' ' << ds[i] << endl;
    }
}