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 <bits/stdc++.h>
const int INF = 500000;
using namespace std;

int main(void){
  bool used[100];
  int n, G[100][100];
  cin >> n;
  for(int i=0; i < 100; i++){
    used[i] = false;
    for(int j=0; j < 100; j++){
      G[i][j] = INF;
    }
  }
  for(int i=0; i < n; i++){
    int vtmp, k;cin >> vtmp >> k;
    for(int j=0; j < k; j++){
      int v, c; cin >> v >> c;
      G[vtmp][v] = c;   
    }
  }

  int d[100];
  for(int i=0; i < n; i++){
    d[i] = INF;
  }
  d[0] = 0;

  for(int i=0; i < n; i++){
    int mind = INF;
    int minind = -1;
    for(int j=0; j < n; j++){
      if(used[j] == false && d[j] < mind){
        mind = d[j]; minind = j;
      }
    }
    if(minind == -1) break;
    used[minind] = true;
    for(int j=0; j < n; j++){
      if(used[j] == false && G[minind][j] != INF){
        if(d[minind] + G[minind][j] < d[j]){
          d[j] = d[minind] + G[minind][j];
        }
      }
    }
  }
  for(int i=0; i < n; i++){
    cout << i << " " << d[i] << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;
#include <functional>

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 100;

int N;

class Edge{
public:
	int from, to, cost;
	Edge(int from = 0, int to = 0, int cost = 0) :
		from(from), to(to), cost(cost){}

	bool operator < (const Edge &e) const{
		return cost < e.cost;
	}
	bool operator >(const Edge &e) const{
		return cost > e.cost;
	}

};

static const int INFTY = (1 << 21);

class Node{
public:
	vector<Edge> edges;
	int dist;
	Node(){
		dist = INFTY;
	}
};

class Graph{
public:
	vector<Node> nodes;
	Graph(int n) {
		rep(i, n) { Node n;  nodes.push_back(n); }
	}
};

class Data{

public:
	int dist; Edge edge;
	Data(int dist, Edge edge) {
		this->dist = dist;
		this->edge = edge;
	}

	bool operator < (const Data &d) const{
		return dist < d.dist;
	}
	bool operator >(const Data &d) const{
		return dist > d.dist;
	}

};

int main() {

	cin >> N;
	Graph g(N);

	rep(i, N){
		int no; cin >> no;
		int n_edge; cin >> n_edge;

		rep(j, n_edge){
			int from = no;
			int to; cin >> to;
			int cost; cin >> cost;
			Edge e(from, to, cost);
			g.nodes[no].edges.push_back(e);
		}
	}

	int i = 0;
	g.nodes[i].dist = 0;

	priority_queue<Data, vector<Data>, greater<Data> > pq;
	for (auto e : g.nodes[i].edges){
		int dist = g.nodes[i].dist + e.cost;
		Data d(dist, e);
		pq.push(d);
	}

	int ret = 0;
	while (!pq.empty()){
		Data d = pq.top(); pq.pop();
		Node *n = &g.nodes[d.edge.to];
		if (n->dist != INFTY){ continue; }
		n->dist = d.dist;

		for (auto e : n->edges){
			int dist = n->dist + e.cost;
			Data d(dist, e);
			pq.push(d);
		}
	}

	rep(i, N){
		cout << i << " " << g.nodes[i].dist << endl;
	}
}

C++: #include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
 
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];

int dijkstra() {
  int u, minv;
  int d[MAX], color[MAX];

  REP(i, n) {
    d[i] = INFTY;
    color[i] = white;
  }

  d[0] = 0;
  color[0] = gray;

  while( 1 ) {
    minv = INFTY;
    u = -1;
    REP(i, n) {
      if (minv > d[i] && color[i] != black ) {
        u = i;
        minv = d[i];
      }
    }
    if (u == -1) break;
    color[u] = black;
    REP(v, n) {
      if (color[v] != black && M[u][v] != INFTY) {
        if (d[v] > d[u] + M[u][v]) {
          d[v] = d[u] + M[u][v];
          p[v] = u;
          color[v] = gray;
        }
      }
    }
  }
  REP(i, n) {
    cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
  }
}

int main() {
  cin >> n;
  REP(i, n) {
    REP(j, n) {
      M[i][j] = INFTY;
    }
  }

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

C++: #include<iostream>
#include<vector>
#include<deque>
#include<queue> 
#include<functional>
#include<climits>

//#define INF 2147483647
#define INF INT_MAX

using namespace std;

int n;
priority_queue<pair<int, int>,  deque<pair<int,int>>, greater<pair<int,int>>> q;
vector<vector<int>> c;
vector<int> d;


int input(){
  cin >> n;
  int u = 0, k = 0, v = 0;
  c.resize(n);
  for( int i = 0; i < n; i++ ){
    cin >> u >> k;
    c[u].resize(n, -1);
    for( int j = 0; j < k; j++ ){
      cin >> v;
      cin >> c[u][v];
    }
  }
  d.resize(n, INF);
  return 0;
}

int checkContinue(){
  for( int i = 0; i < n; i++ ){
    if( d[i] == INF ){ return 1; }
  }
  return 0;
}

int run(){
  q.emplace(pair<int,int>(0,0));
  while( checkContinue() ){
    pair<int, int> p = q.top();
    q.pop();
    if( d[p.second] < p.first ){ continue; }
    d[p.second] = p.first;
    for( int i = 0; i < n; i++ ){
      if( c[p.second][i] < 0 ){ continue; }
      q.push(pair<int,int>(p.first+c[p.second][i], i));
      // cout << p.first+c[p.second][i] << "," << i << endl;
    }
  }
  for( int i = 0; i < n; i++ ){
    cout << i << " " << d[i] << endl;
  }
  return 0;
}

int main(){
  input();
  run();
  return 0;
}