Go: package main

import (
	"fmt"
	"container/heap"
)

type Node struct {
	Id int
	Dis int
}

type PriorityQueue []*Node

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dis < pq[j].Dis
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(*Node))
}

func (pq *PriorityQueue) Pop() interface{} {
	n := len(*pq)
	pop := (*pq)[n-1]
	*pq = (*pq)[0:n-1]
	return pop
}

func main() {
	var n int
	fmt.Scan(&n)

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
			fmt.Scan(&c[u][j])
		}

		if u == 0 {
			d[u] = 0
		} else {
			d[u] = 1 << 30
		}
		pq.Push(&Node{u, d[u]})
	}
	heap.Init(&pq)

	for pq.Len() > 0 {
		node := heap.Pop(&pq).(*Node)
		for i := 0; i < len(g[node.Id]); i++ {
			nextId := g[node.Id][i]
			nextDis := node.Dis + c[node.Id][i]
			if nextDis < d[nextId] {
				d[nextId] = nextDis
				heap.Push(&pq, &Node{nextId, nextDis})
			}
		}
	}

	for i := 0; i < n; i++ {
		fmt.Println(i, d[i])
	}
}

C++: #include<iostream>
#include<vector>
#include<queue>
using namespace std;
template< typename FirstType, typename SecondType >
struct PairComparator {
  bool operator()( const pair<FirstType, SecondType>& p1, const pair<FirstType, SecondType>& p2 ) const 
    {  
		return p1.first > p2.first;
    }
};
bool inMST(vector< std::pair<int,int> > & MST,int j) {
	for (int k=0;k<(int)MST.size();++k){
		if(j == MST[k].second)
			return true;
	}
	return false;
}
int main(){
	int n;
	cin >> n;
	vector<int> E(n*n,-1);
	vector<int> DPG(n,-1);
	vector< std::pair<int,int> > MST;
	for(int j=0;j<n;++j) {
		int u,k; 
		cin >> u >> k;
		for(int i=0;i<k;++i){
			int v,c;
			cin >> v >> c;
			E[u*n+v] = c;
			E[u+v*n] = c;
		}
	}
	priority_queue<pair<int,pair<int,int> >,vector< pair<int,pair<int,int> > >,
		PairComparator<int,pair<int,int> > > r;

	//put Node 0
	int cost = 0;
	int i=0;
	MST.push_back(pair<int,int>(i,i));
	DPG[i] = 0;
	while((int)MST.size() < n) {
		int ii=i*n;
		for (int j=0;j<n;++j) {
			if (E[ii+j] >= 0) {
				pair<int,int> add = std::make_pair(i,j);
				if (!inMST(MST,add.second)){
					r.push(std::pair<int,std::pair<int,int> >(E[ii+j],add));
				}
			}
		}
		pair<int,pair<int,int> > top;
		while (!r.empty()) {
			top = r.top();
			r.pop();
			if (!inMST(MST,top.second.second)){
				break;
			}
		}
		cost += top.first;
		MST.push_back(top.second);
		i = top.second.second;
		DPG[i] = DPG[top.second.first] + top.first;
		for(int j=0;j<n;++j){
			if (DPG[j] < 0)continue;
			if (E[i*n+j] < 0)continue;
			DPG[j] = std::min(DPG[j],DPG[i] + E[i*n+j]);
		}
	}
	for (int j=0;j<n;++j) {
		cout << j << " " <<  DPG[j] << endl;
	}
}

C++: #include <algorithm>
#include <iostream>
#include <list>
#include <vector>

class TNode
{
	std::list<std::pair<TNode*, int> > FNexts;
	int  FDistance;
public:
	TNode()
	: FDistance(-1)
	{
	}
	
	int GetDistance()const {return FDistance;}
	
	void Push(TNode* New, int Weight)
	{
		FNexts.push_back(std::make_pair(New, Weight));
	}
	
	void Visit(int Distance)
	{
		if(FDistance >= 0 && Distance > FDistance) return;
		FDistance = Distance;
		for(std::list<std::pair<TNode*, int> >::iterator It = FNexts.begin(); It != FNexts.end(); ++It){
			It->first->Visit(Distance + It->second);
		}
	}
};

class TGraph
{
	std::vector<TNode*> FNodes;
public:
	TGraph(int Count)
	: FNodes(Count)
	{
		for(int i = 0; i < Count; ++i){
			FNodes[i] = new TNode();
		}
	}
	
	~TGraph()
	{
		for(unsigned int i = 0; i < FNodes.size(); ++i){
			delete FNodes[i];
		}
	}
	
	void InputNode()
	{
		int Index;
		std::cin >> Index;
		int BranchCount;
		std::cin >> BranchCount;
		for(int i = 0; i < BranchCount; ++i){
			int Target, Weight;
			std::cin >> Target >> Weight;
			FNodes[Index]->Push(FNodes[Target], Weight);
		}
	}
	
	void BreathFirstSearch()
	{
		FNodes[0]->Visit(0);
	}
	
	int Distance(int Target)const
	{
		return FNodes[Target]->GetDistance();
	}
};

int main()
{
	int Count;
	std::cin >> Count;
	TGraph Graph(Count);
	for(int i = 0; i < Count; ++i){
		Graph.InputNode();
	}
	Graph.BreathFirstSearch();
	
	for(int i = 0; i < Count; ++i){
		std::cout << i << " " << Graph.Distance(i) << std::endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int white=01;
static const int gray=1;
static const int black=2;

int n,M[MAX][MAX];
void dijkstra(){
    int minv;
    int d[MAX],color[MAX];

    for(int i=0;i<n;i++){
	d[i]=INFTY;
	color[i]=white;
    }
    d[0]=0;
    color[0]=gray;
    while(1){
	minv=INFTY;
	int u=-1;
	for(int 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(int 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(int i=0;i<n;i++){
	cout<<i<<" "<<(d[i]==INFTY?-1:d[i])<<endl;
    }
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
	    M[i][j]=INFTY;
	}
    }

    int k,c,u,v;
    for(int i=0;i<n;i++){
	cin>>u>>k;
	for(int j=0;j<k;j++){
	    cin>>u>>c;
	    M[u][v]=c;
	}
    }
    dijkstra();
    return 0;
}

C++: #include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra(){
    int minv;
    int d[MAX], color[MAX];
    
    for(int i = 0; i < n; i++){
        d[i] = INFTY;
        color[i] = WHITE;
    }
    
    d[0] = 0;
    color[0] = GRAY;
    while(1){
        minv = INFTY;
        int u = -1;
        for(int 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(int 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(int i = 0; i < n; i++){
        cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            M[i][j] = INFTY;
        }
    }
    
    int k, c, u, v;
    for(int i = 0; i < n; i++){
        cin >> u >> k;
        for(int j = 0; j < k; j++){
            cin >> v >> c;
            M[u][v] = c;
        }
    }
    
    dijkstra();
    
    return 0;
}

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

#define INF (1 << 21)

int main() {
	int node_num;

	std::cin >> node_num;
	std::vector<std::vector<int> > node(node_num, std::vector<int>(node_num, -1));

	for (size_t i = 0; i < node.size(); i++) {
		int out, node_number;
		std::cin >> node_number >> out;
		for (int j = 0; j < out; j++) {
			int to, distance;
			std::cin >> to >> distance;
			node[node_number][to] = distance;
		}
	}

	std::vector<int> distance(node.size(), INF);
	distance[0] = 0;

	int node_number = 0;
	for (size_t i = 0; i < node.size(); i++) {
		int min = INF;
		for (size_t j = 0; j < node[i].size(); j++) {
			if (node[node_number][j] != -1 && node[node_number][j] + distance[node_number] < distance[j]) {
				distance[j] = node[node_number][j] + distance[node_number];
				if (min == INF) {
					min = j;
				}else if (distance[min] > distance[j]) {
					min = j;
				}
			}
		}
		node_number = min;
		if (node_number == INF) break;
	}

	for (size_t i = 0; i < distance.size(); i++) {
		std::cout << i << " " << distance[i] << std::endl;
	}
}