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>
#define INF 1<<30
#define FinishFunction return 0
#define MAX 1000000
using namespace std;
    
struct edge {
  int from,to,cost,k;
};
  
edge es[MAX];
  
int main(){
  int n,u,k,E,c,v;
  E = 0;
  scanf("%d",&n);
  
  for(int i=0;i<n;i++){
    scanf("%d %d",&u,&k);
     
    for(int j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      es[E].from = u;
      es[E].to = v;
      es[E++].cost = c;
    }
  }
  
  // Ika berumanfo-do   
  int d[MAX];
  for(int i=0;i<n;i++)d[i] = INF;
  d[0] = 0;
  while(true){
    bool update = false;
    for(int i=0;i<E;i++){
      edge e = es[i];
      if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
    d[e.to] = d[e.from] + e.cost;
    update = true;
      }
    }
    if(!update)break;
  }
  for(int i=0;i<n;i++)cout << i << " " << d[i] << endl;
  FinishFunction;// return 0
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
#define INT_MAX 2147483647
#define INT_MIN -2147483646
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
void fastios() { ios_base::sync_with_stdio(0); cin.tie(0); }

static const int N = 10005;

struct vertex {
	int id;
	int p;
	int d;
	bool operator<(const vertex & another) const {
		return (d != another.d ? d>another.d : id>another.id);
	}
};

struct edge {
	int end;
	int w;
};

int main() {
	fastios();
	int n;
	cin >> n;
	vector<vector<edge>> E(N);
	Loop(i, n) {
		int u, k;
		cin >> u >> k;
		Loop(i, k) {
			int v, c;
			cin >> v >> c;
			E[u].push_back({ v,c });
		}
	}
	//
	priority_queue<vertex> pq;
	vi color(N, 0), dist(N, 0);
	pq.push({ 0,-1,0 });
	int cnt = 0;
	while (pq.size() > 0) {
		if (cnt == n) break;
		vertex v = pq.top();
		pq.pop();
		if (color[v.id] == 1) continue;
		dist[v.id] = v.d;
		color[v.id] = 1;
		cnt++;
		Loop(j, E[v.id].size()) {
			pq.push({ E[v.id][j].end, v.id, dist[v.id] + E[v.id][j].w });
		}
	}
	Loop(i, n) {
		cout << i << " " << dist[i] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>

using namespace std;

class SSSPath
{
public:
  int solve();
};

int SSSPath::solve()
{
  int n;
  cin >> n;

  vector<vector<pair<int, int>>> adj( n );

  for ( auto i = 0; i < n; ++i )
    {
      int k, u, v, w;

      cin >> u >> k;

      for ( auto j = 0; j < k; ++j )
        {
          cin >> v >> w;
          adj[u].push_back( make_pair( v, w ) );
        }
    }

  const int infty = 2000000000;
  
  vector<int> d( n, infty );
  vector<bool> vs( n, true );
  
  d[0] = 0;

  while ( true )
    {
      int u, mc = infty;

      for ( auto i = 0; i < n; ++i )
        {
          if ( vs[i] && d[i] < mc )
            {
              mc = d[i];
              u = i;
            }
        }

      if ( mc == infty ) break;
      
      vs[u] = false;

      for ( auto it = adj[u].begin(); it != adj[u].end(); ++it )
        {
          if ( d[(*it).first] > d[u] + (*it).second )
            {
              d[(*it).first] = d[u] + (*it).second;
            }
        }
    }

  for ( auto i = 0; i < n; ++i )
    cout << i << " " << d[i] << endl;
  
  return 0;
}

int main()
{
  SSSPath s;

  s.solve();

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

#define MAX 10000
#define INF (1<<20)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n;
vector<pair<int,int> > adj[MAX];

void dijkstra(int s){
    priority_queue<pair<int,int> > PQ;
    int d[MAX], color[MAX];

    rep(i,n){
        color[i] = WHITE;
        d[i] = INF;
    }

    d[s] = 0;
    PQ.push(make_pair(0, s));

    while(!PQ.empty()){
        pair<int,int> f = PQ.top(); PQ.pop();
        int u = f.second;
        color[u] = BLACK;

        //if(d[u] < f.first * (-1)) continue;

        for(int i = 0; i < adj[u].size(); i++){
            int v = adj[u][i].first;
            int c = adj[u][i].second;
            if(color[v] == BLACK) continue;
            if(d[v] > d[u] + c){
                d[v] = d[u] + c;
                PQ.push(make_pair((-1)*d[v], v));
            }
        }
    }

    for(int i = 0; i < n; i++){
        cout << i << " " << d[i] << endl;
    }
}

int main(){
    cin >> n;
    int u, k, v, c;
    rep(i,n){
        cin >> u >> k;
        rep(j,k){
            cin >> v >> c;
            adj[u].push_back(make_pair(v, c)); 
        }
    }

    dijkstra(0);

    return 0;
}