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 <cstdio>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

using Weight=int;
using DArray=vector<Weight>;
using DMatrix=vector<DArray>;

static const Weight INF=1<<29;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

template <class T>
using lp_queue=priority_queue<T, deque<T>, greater<T>>;

template <typename T, typename U=size_t>
union raw_cast {
    public:
        constexpr raw_cast(T t): _t(t) {}
        operator U() const {
            return _u;
        }

    private:
        T _t;
        U _u;
};

size_t bsr(size_t n) {
    /* Bit scan reverse */
    // logarithmus binarius
    if (!n) return -1;

    size_t res;
    for (res=0; n>>=1; ++res)
        if (!n) return res;

    return res;
}

template <class Index, class T, size_t bucketSize=sizeof(Index)<<3>
struct RadixHeap {
    vector<pair<Index, T>> v[bucketSize|1];
    Index last;
    size_t size_;
    RadixHeap(): last(0), size_(0) {}
    void push(Index n, T t) {
        if (last > n) return;

        ++size_;
        size_t idx=raw_cast<Index>(n);
        idx ^= raw_cast<Index>(last);
        v[bsr(idx)+1].push_back(make_pair(n, t));
    }
    void push(pair<Index, T> p) {
        push(p.first, p.second);
    }
    void pop() {
        if (!size_) return;
        if (!v[0].size()) {
            size_t i; for (i=1; !v[i].size(); ++i);
            last = min_element(v[i].begin(), v[i].end())->first;
            for (const pair<Index, T> &p: v[i]) {
                size_t idx=raw_cast<Index>(p.first);
                idx ^= raw_cast<Index>(last);
                v[bsr(idx)+1].push_back(p);
            }

            v[i].clear();
        }
        --size_;
        v[0].pop_back();
    }
    pair<Index, T> top() {
        if (!size_) return pair<Index, T>();
        if (!v[0].size()) {
            size_t i; for (i=1; !v[i].size(); ++i);
            last = min_element(v[i].begin(), v[i].end())->first;
            for (const pair<Index, T> &p: v[i]) {
                size_t idx=raw_cast<Index>(p.first);
                idx ^= raw_cast<Index>(last);
                v[bsr(idx)+1].push_back(p);
            }

            v[i].clear();
        }
        return v[0].back();
    }
    size_t size() {
        return size_;
    }
    bool empty() {
        return !size_;
    }
    void clear() {
        last = size_ = 0;
        for (size_t i=0; i<=bucketSize; ++i)
            v[i].clear();
    }
};

vector<Weight> shortest_distance(const Graph &g, size_t s) {
    /* Dijkstra */
    size_t V=g.size();
    vector<Weight> d(V, INF); d[s]=0;

    RadixHeap<Weight, size_t> q; q.push(0, s);
    while (!q.empty()) {
        pair<Weight, size_t> p=q.top(); q.pop();
        size_t v=p.second;
        if (d[v] < p.first) continue;

        for (const Edge &e: g[v])
            if (d[e.dst] > d[v] + e.weight) {
                d[e.dst] = d[v] + e.weight;
                q.push(d[e.dst], e.dst);
            }
    }
    return d;
}

int main() {
    size_t n;
    scanf("%zu", &n);

    Graph g(n);
    for (size_t i=0; i<n; ++i) {
        size_t u, k;
        scanf("%zu %zu", &u, &k);

        for (size_t j=0; j<k; ++j) {
            size_t c;
            Weight v;
            scanf("%zu %d", &c, &v);

            connect(g, u, c, v);
        }
    }

    vector<Weight> d=shortest_distance(g, 0);
    for (size_t i=0; i<n; ++i)
        printf("%zu %d\n", i, d[i]);

    return 0;
}

C++: #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int MAX=105;
const int INF= 1<<30;
int M[MAX][MAX],n,d[MAX],p[MAX],vis[MAX];
void init(){
	for(int i=0;i<n;i++){
		d[i]=INF;
		p[i]=-1;
		vis[i]=0;
	}
	d[0]=0;
}
void dijkstra(){
	init();
	while (true){
		int u=-1;
		int minCost=INF;
		for(int i=0;i<n;i++){
			if(!vis[i] && d[i]<minCost){
				u=i;
				minCost=d[i];
			}
		}
		if(u==-1)break;
		vis[u]=1;
		for(int i=0;i<n;i++){
			if(!vis[i] && M[u][i]!=-1 &&M[u][i]+d[u]<d[i]){
				d[i]=M[u][i]+d[u];
				p[i]=u;
			}
		}
	}
}
int main(){
	cin>>n;
	memset(M,-1,sizeof(M));
	for(int i=0;i<n;i++){
		int u,k,v,c;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			cin>>v>>c;
			M[u][v]=c;
		}
	}
	dijkstra();
	for(int i=0;i<n;i++){
		printf("%d %d\n",i,d[i]);
	}
	return 0;
}