Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)

	g := makeGraph(n)
	for i := 0; i < n; i++ {
		u := getNextInt(scanner)
		k := getNextInt(scanner)
		for ii := 0; ii < k; ii++ {
			v := getNextInt(scanner)
			c := getNextInt(scanner)
			g[u][v] = c
		}
	}

	ans := make([]int, n)
	im := make(IntMap, 1)
	im.increment(0)
	for len(im) < n {
		min := 1 << 30
		x := -1
		for u := range im {
			for v := 0; v < n; v++ {
				if im.get(v) != 0 {
					continue
				}
				if min > ans[u]+g[u][v] {
					min = ans[u] + g[u][v]
					x = v
				}
			}
		}
		im.increment(x)
		ans[x] = min
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", i, ans[i]))
	}
	writer.Flush()
}

func makeGraph(n int) [][]int {
	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		for ii := 0; ii < n; ii++ {
			g[i][ii] = 1 << 30
		}
	}

	return g
}

// IntMap ...
type IntMap map[int]int

func (m IntMap) get(key int) int {
	if _, ok := m[key]; ok {
		return m[key]
	}
	return 0
}
func (m IntMap) increment(key int) {
	if _, ok := m[key]; ok == false {
		m[key] = 0
	}
	m[key]++
}

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

class Nodes;

class Node {
public:
    Node(int n) : id(n), cost(INT_MAX) { }
    void addEdge(int to, int cost) { edgesTo.push_back(to); edgesCost.push_back(cost); }
    int getId() { return id; }
    int getCost() { return cost; }
    void setCost(int alt) { cost = alt; }
    void print() { std::cout << id << " " << cost << std::endl; }
    void printAll() {
        std::cout << id << " " << cost;
        for (std::vector<int>::iterator itr = edgesTo.begin(), itr2 = edgesCost.begin();  itr != edgesTo.end(); ++itr, ++itr2) {
            std::cout << " " << *itr << " " << *itr2;
        }
        std::cout << std::endl;
    }
    void updatesCost(Nodes* nodes);
private:
    int id;
    std::vector<int> edgesTo;
    std::vector<int> edgesCost;
    int cost;
};

class Nodes {
public:
    void readFromIn() {
        int size;
        std::cin >> size;
        for (int i=0; i<size; ++i) {
            int id;
            int sizeOfEdges;
            std::cin >> id >> sizeOfEdges;
            Node *node = new Node(id);
            for (int j=0; j<sizeOfEdges; ++j) {
                int to;
                int cost;
                std::cin >> to >> cost;
                node->addEdge(to, cost);
                //std::cout << to << cost << std::endl;
            }
            nodes.push_back(node);
        }
        nodes[0]->setCost(0);
    }
    std::vector<Node*>::iterator findNodeWithTheLeastDistance(std::vector<Node*> &queue) {
        std::vector<Node*>::iterator min=queue.begin();
        for (std::vector<Node*>::iterator itr=queue.begin()+1; itr != queue.end(); ++itr) {
            if ((*min)->getCost() > (*itr)->getCost()) {
                min = itr;
            }
        }
        return min;
    }
    void dijkstrasAlgorithm() {
        std::vector<Node*> queue(nodes);

        while (!queue.empty()) {
            std::vector<Node*>::iterator u = findNodeWithTheLeastDistance(queue);
            int n = (*u)->getId();
            //std::cout << "**" << n << std::endl;
            queue.erase(u);

            getNode(n)->updatesCost(this);
        }
    }
    void print() {
        for (std::vector<Node*>::iterator itr=nodes.begin(); itr != nodes.end(); ++itr) {
            (*itr)->print();
        }
    }
    Node* getNode(int n) {
        return nodes[n];
    }
private:
    std::vector<Node*> nodes;
};

void Node::updatesCost(Nodes* nodes) {
    for (std::vector<int>::iterator itr = edgesTo.begin(), itr2 = edgesCost.begin();  itr != edgesTo.end(); ++itr, ++itr2) {
    Node* v = nodes->getNode(*itr);
    int alt = cost + *itr2;
    if (alt < v->getCost()) {
        v->setCost(alt);
    }
    //nodes->print();
}
    /*
for (i=0; i<nodes[u]->sizeOfEdges; ++i) {
    int v = nodes[u]->edgesTo[i];
    int alt = nodes[u]->cost + nodes[u]->edgesCost[i];
    if (alt < nodes[v]->cost) {
        nodes[v]->cost = alt;
    }
}
*/
}

int main(int argc, char *argv[])
{
    Nodes nodes;

    nodes.readFromIn();
    nodes.dijkstrasAlgorithm();
    nodes.print();
    return 0;
}

C++: //さっさと済ませられるところはさっさと済ましてしまう．ただし注意深く
#include <cstdio>
#include <iostream>
#define MAX_VERTEXES 100
#define NIL -1
#define INFTY 20000000// >100*100000

using namespace std;

//think easy make easy

int n;//num of vertexes(頂点)
int matrix_graph[MAX_VERTEXES+1][MAX_VERTEXES+1];//0オリジン
bool vertex_set[MAX_VERTEXES+1];///0オリジン
int current_mincost[MAX_VERTEXES+1];//現時点での各頂点への最小コスト
bool candidate[MAX_VERTEXES+1];//次にvertex_setに加える頂点の候補

void findNextVertex(){
	int min_tmp=INFTY;
	int next_tmp = NIL;
	for(int i=0;i<n;i++){
		candidate[i] = false;
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(vertex_set[i] == true && vertex_set[j] == false){
				if(matrix_graph[i][j]+current_mincost[i] < current_mincost[j]
				   && matrix_graph[i][j] != NIL){
					   current_mincost[j]  = matrix_graph[i][j]+current_mincost[i];
					   candidate[j] = true;
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		if(candidate[i] == true && current_mincost[i] < min_tmp){
			min_tmp = current_mincost[i];
			next_tmp = i;
		}
	}
	vertex_set[next_tmp] = true;
}

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

	int v_num;
	int k;//v_numの出次数

	for(int i=0;i<n;i++){
		for(int j=0;j<=n;j++){
			matrix_graph[i][j] = NIL;
		}
	}

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

		for(int j=0;j<k;j++){
			int v_num2;
			int cst;
			scanf("%d",&v_num2);
			scanf("%d",&cst);
			matrix_graph[v_num][v_num2] = cst;
		}
	}

	for(int i=0;i<n;i++){
		vertex_set[i] = false;
		current_mincost[i] = INFTY;
	}
	/*確認用
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(j<n-1) printf("%d ",matrix_graph[i][j]);
			else printf("%d\n",matrix_graph[i][j]);
		}
	}
	*/

	vertex_set[0] = true;
	current_mincost[0] = 0;
	for(int i=1;i<n;i++){
		findNextVertex();
	}
	for(int i=0;i<n;i++){
		cout <<i <<" " <<current_mincost[i] <<endl;
	}


	return 0;
}

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

using namespace std;

struct Wside{
	int vertex;
	int weight;
	Wside(int a, int b){
		vertex=a; weight=b;
	}
};

vector<Wside>* info;
vector<int> scanned;
int* result;
int n, mark;

bool isScanned(int v){
	for(int i=0,sz=scanned.size(); i<sz; ++i){
		if(v==scanned[i]) return 1;
	}
	return 0;
}

int scan(){
	int nextvtx = -1;
	for(int j=0, scn=scanned[scanned.size()-1], sz=info[scn].size(); j<sz; ++j){
		int vtx = info[scn][j].vertex;
		if(isScanned(vtx)) continue;
		int wgh = info[scn][j].weight;
		result[vtx] = result[vtx] > result[scn] + wgh ? (result[scn] + wgh) : result[vtx];
	}

	for(int i=0; i<n; ++i){
		if(!isScanned(i)){
			if(nextvtx == -1){
				nextvtx = i;
				continue;
			}
			nextvtx = result[nextvtx] < result[i]? nextvtx : i ;
		}
	}
	scanned.push_back(nextvtx);
	return 0;
}

int main()
{
	scanf("%d",&n);
	scanned.reserve(n);
	info = new vector<Wside> [n];
	result = new int [n];
	for(int i=0; i<n; ++i){
		result[i] = 0xfffffff;
	}

	int org,k,v,c;
	for(int i=0; i<n; ++i){
		scanf("%d %d",&org,&k);
		info[org].reserve(k);
		for(int j=0; j<k; ++j){
			scanf("%d %d",&v,&c);
			info[org].push_back(Wside(v,c));
		}
	}

	scanned.push_back(0);
	result[0] = 0;
	while(scanned.size()!=n){
		scan();
	}

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

	delete[] info;
	delete[] result;

	return 0;
}