Go: package main

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

//make priority queue
type Item struct {
	id       int
	priority int // this state is priority and distans from start
	index    int
}

type PriorityQueue []*Item

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

// we want the ascending-priority-queue.
// So we use less than here.
func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}

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

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1 //for safety
	*pq = old[0 : n-1]
	return item
}

func (pq *PriorityQueue) update(dist int, id int) {
	for _, i := range *pq {
		if i.id == id {
			if i.priority > dist {
				i.priority = dist
			}
		}
	}
}

// the main code
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func dikstra(dist [][]int, n int) []int {
	// preparate priority queue
	inf := 1 << 30
	pq := make(PriorityQueue, n)
	shortests := make([]int, n)
	for i := 0; i < n; i++ {
		pq[i] = &Item{
			id:       i,
			priority: inf,
			index:    i,
		}

		shortests[i] = inf
	}
	pq[0].priority = 0
	shortests[0] = 0
	heap.Init(&pq)

	for pq.Len() > 0 {
		item := heap.Pop(&pq).(*Item)
		shortests[item.id] = item.priority
		for id, d := range dist[item.id] {
			if d != -1 {
				pq.update(item.priority+d, id)
			}
		}
		heap.Init(&pq)
	}
	return shortests
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	// init
	n := nextInt(sc)
	dist := make([][]int, n)
	for i := 0; i < n; i++ {
		dist[i] = make([]int, n)
		for j := 0; j < n; j++ {
			dist[i][j] = -1
		}
	}

	// std Input
	for i := 0; i < n; i++ {
		u := nextInt(sc)
		k := nextInt(sc)
		for j := 0; j < k; j++ {
			v, c := nextInt(sc), nextInt(sc)
			dist[u][v] = c
		}
	}

	shortests := dikstra(dist, n)
	for i, d := range shortests {
		fmt.Printf("%d %d\n", i, d)
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

// ---------------------
// repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF (1 << 21)
typedef long long ll;

int main() {
  int n;
  cin >> n;

  vector<int> V[n];
  int E[n][n];
  int d[n];
  int visited[n];

  REP(x, n) {
    REP(y, n) {
      E[x][y] = INF;
    }
    d[x] = INF;
    visited[x] = 0;
  }

  REP(_, n) {
    int u, k;
    cin >> u >> k;
    REP(__, k) {
      int v, c;
      cin >> v >> c;
      V[u].push_back(v);
      E[u][v] = c;
      E[v][u] = c;
    }
  }

  d[0] = 0;
  REP(_, n) {
    int minv = -1;
    int mincost = INF;
    REP(v, n) {
      if (!visited[v] && d[v] < mincost) {
        minv = v;
        mincost = d[v];
      }
    }
    visited[minv] = 1;
    for (vector<int>::iterator it = V[minv].begin(); it != V[minv].end(); it++) {
      if (E[minv][*it] < INF && d[minv] + E[minv][*it] < d[*it]) {
        d[*it] = d[minv] + E[minv][*it];
      }
    }
  }

  REP(i, n) {
    cout << i << " " << d[i] << endl;
  }
  return 0;
}

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

using namespace std;
#define MAX 100
#define WHITE 0
#define BLACK 1

int W[MAX][MAX],color[MAX],d[MAX],p[MAX];
int n,u,k,v,c;

int Djs()
{
   int minv,u;
   d[0]=0;
   while(1)
   {
    minv=INT_MAX;
     u=-1;
    for(int i=0;i<n;i++)
    {
       if(d[i]<minv&&color[i]!=BLACK)
       {
           minv=d[i];
           u=i;
       }
    }
    if(u==-1) break;
    color[u]=BLACK;
    for(int v=0;v<n;v++)
    {
       if(W[u][v]!=INT_MAX&&color[v]!=BLACK)
       {
           if(d[u]+W[u][v]<d[v])
           {
               d[v]=d[u]+W[u][v];
               p[v]=u;
           }
       }
    }
   }
   for(int i=0;i<n;i++)
   {
       cout<<i<<" "<<d[i]<<endl;
   }
}

int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
     d[i]=INT_MAX;
     p[i]=-1;
     for(int j=0;j<n;j++)
     {
        W[i][j]=INT_MAX;
     }
    }
    for(int i=0;i<n;i++)
    {
     cin>>u>>k;
     for(int j=0;j<k;j++)
     {
        cin>>v>>c;
        W[u][v]=c;
     }
    }
    Djs();
    return 0;
}

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