Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const (
	INFTY = 1 << 21
	NIL   = -1
)

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph [][]int

func (g *Graph) dikstra(n int) string {
	var (
		u, minv = 0, 0
	)

	d := make([]int, n)
	color := make([]int, n)

	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 && (*g)[u][v] != INFTY {
				if d[v] > d[u]+(*g)[u][v] {
					d[v] = d[u] + (*g)[u][v]
					color[v] = GRAY
				}
			}
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d ", i))
		if d[i] == INFTY {
			out.WriteString(fmt.Sprintf("%d\n", -1))
			continue
		}
		out.WriteString(fmt.Sprintf("%d\n", d[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	g := make(Graph, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		for j := 0; j < n; j++ {
			g[i][j] = INFTY
		}
	}

	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := 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())

			g[u][v] = c
		}
	}

	return g.dikstra(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

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;
}