Go: package main

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

const MAX = 100
const INFTY = math.MaxInt64
const WHITE = 0
const GRAY = 1
const BLACK = 2

var n int
var M [MAX][MAX]int

func dijkstra() {
	var minv int
	var d [MAX]int
	var color [MAX]int

	for i := 0; i < n; i++ {
		d[i] = INFTY
		color[i] = WHITE
	}

	d[0] = 0
	color[0] = GRAY
	for {

		minv = INFTY
		u := -1
		for i := 0; i < n; i++ {
			if minv > d[i] && color[i] != BLACK {
				u = i
				minv = d[i]
			}
		}
		if u == -1 {
			break
		}

		color[u] = BLACK

		for v := 0; v < n; v++ {
			if color[v] != BLACK && M[u][v] != INFTY {
				if d[v] > d[u]+M[u][v] {
					d[v] = d[u] + M[u][v]
					color[v] = GRAY
				}
			}
		}

	}
	for i := 0; i < n; i++ {
		fmt.Printf("%v %v\n", i, d[i])
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ = strconv.Atoi(sc.Text())

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			M[i][j] = INFTY
		}
	}

	for i := 0; i < n; i++ {
		sc.Scan()
		f, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			sc.Scan()
			c, _ := strconv.Atoi(sc.Text())
			M[f][v] = c
		}
	}
	dijkstra()
}

C++: #include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#define NMAX 100
#define INF 100000000

//??????????????¢??????????????¨debug()??????????????????
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef pair<int ,int > P;
typedef long long ll;

int N,ans = 0;
int d[NMAX] = {};
vector<P> connect[NMAX];

void solve(){
	d[0] = 0;
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(P(0,0));
	while(!que.empty()){
		P p = que.top();
		// cout << "P(" << p.first << "," << p.second << ")\n";
		que.pop();
		int v = p.first;
		if(d[v] < p.second) continue;
		for (int i = 0; i < connect[v].size(); ++i)
		{
			if(d[connect[v][i].first] > d[v] + connect[v][i].second){
				d[connect[v][i].first] = d[v] + connect[v][i].second;
				que.push(P(connect[v][i].first,d[connect[v][i].first]));
			}
		}
	}
}

void debug(){

}

void answer(){
	for (int i = 0; i < N; ++i)
	{
		cout << i << " " << d[i] << "\n";
	}
}

int main(){
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		int a,b;
		cin >> a >> b;
		for (int j = 0; j < b; ++j)
		{
			int k,l;
			cin >> k >> l;
			connect[a].push_back(P(k,l));
		}
	}
	Fill(d,INF);
	solve();
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

C++: #include <stdio.h>
#include <vector>
#include <list>
#include <map>
#include <array>
#include <memory>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <stdexcept>
#include <numeric>
#include <queue>

using std::string;
using std::vector;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// util
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

std::vector<std::string> split(const std::string& input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// user func
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void printList(const vector<int>& list) {
    // print
    for(int i = 0; i < list.size(); i++){
        printf("%d", list[i]);
        if ( i + 1 != list.size() ) {
            printf(" ");
        }
    }
    printf("\n");
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// logic
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

static int MAX = 1000000;

class Node{
public:
    Node(int id, int numEdge)
     : id(id)
     , edges(vector<int>(numEdge, MAX))
    {
        // constructer
    }
    
    void Edge(int id, int weight){
        this->edges[id] = weight;
    }

    vector<int> Edges() {
        return this->edges;
    }

    int id;
    bool done = false;
    vector<int> edges;
};

class List{
public:
    // constructer
    List(int numNode)
        : results(numNode)
    {
        for (int i = 0; i < numNode; i++) {
            this->nodes.push_back(Node(i, numNode));
            this->results[i] = MAX;
        }
    }

    void SetWeight(int from, int to, int weight)
    {
        this->nodes[from].Edge(to, weight);
    }
    
    vector<int> ShortedPath() {
        // this->Enqueue(0);
        this->results[0] = 0;
        this->queue.push(0);
        this->Traverse();
        return this->results;
    }

    void Traverse() {
        while(!this->queue.empty()) {
            int queueIndex = queue.front();
            queue.pop();
            vector<int> edges = this->nodes[queueIndex].Edges();
            for (int i = 0; i < edges.size(); i++) {
                // update result
                int myWeight = this->results[queueIndex];
                this->results[i] = std::min(this->results[i], myWeight + edges[i]);
            }
            // printList(this->results);
            // enqueue
            this->Enqueue(queueIndex);
            // done flag
            this->nodes[queueIndex].done = true;
        }
    }

    void Enqueue(int index) {
        // copy weights
        if (this->nodes[index].done) return;
        std::list<std::pair<int, int>> weights;
        for (int i = 0; i <  this->nodes[index].Edges().size(); i++) {
            weights.push_back(std::make_pair(i, this->nodes[index].Edges()[i]));
        }
        // sort
        weights.sort([](auto& lhs, auto& rhs){
            return lhs.second < rhs.second;
        });
        // enqueue
        for (auto weight : weights){
            queue.push(weight.first);
        }
    }
    
    

    void Print() {
        for (int i = 0; i < this->nodes.size(); i++) {
            printf("%d: ", i);
            for (int j = 0; j < this->nodes[i].Edges().size(); j++) {
                printf("%d (%d) ", j, this->nodes[i].Edges()[j]);
            }
            printf("\n");
        }
    }
private:
    std::queue<int> queue;
    std::vector<int> results;
    vector<Node> nodes;
};

void solve() {

    int n;
    scanf("%d", &n);
    List list(n);

    for (int i = 0; i < n; i++){
        int key;
        scanf("%d", &key);
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int dest;
            int weight;
            scanf("%d %d", &dest, &weight);
            list.SetWeight(key, dest, weight);
        }
    }
    // list.Print();
    auto result = list.ShortedPath();
    for(int i = 0; i < result.size(); i++) {
        printf("%d %d\n", i, result[i]);
    }
}

void test(){

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