Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

const NIL = -1

type Node struct {
	id     int
	weight int
}

func init() {
	sc.Split(bufio.ScanWords)
}

type NodeHeap []Node

func (h NodeHeap) Len() int           { return len(h) }
func (h NodeHeap) Less(i, j int) bool { return h[i].weight < h[j].weight }
func (h NodeHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *NodeHeap) Push(x interface{}) {
	*h = append(*h, x.(Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()

	list := make([][]int, n)
	weight := make([]int, n)
	for i := range list {
		list[i] = make([]int, n)
		weight[i] = NIL
		for j := range list[i] {
			list[i][j] = NIL
		}
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		for j := 0; j < k; j++ {
			v := scanInt()
			w := scanInt()
			list[u][v] = w
		}
	}

	start := Node{id: 0, weight: 0}
	h := &NodeHeap{start}
	heap.Init(h)

	for h.Len() > 0 {
		node := heap.Pop(h).(Node)
		if weight[node.id] != NIL {
			continue
		}
		weight[node.id] = node.weight

		for i, w := range list[node.id] {
			if w == NIL {
				continue
			}
			heap.Push(h, Node{id: i, weight: w + node.weight})
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		fmt.Fprint(w, i)
		fmt.Fprint(w, " ")
		fmt.Fprint(w, weight[i])
		fmt.Fprintln(w)
	}
	w.Flush()
}

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