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<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef pair< int, int > Pi;
const int INF = 1 << 30;
struct edge: vector< Pi > {
  void add_edge(int to, int cost){
    push_back(Pi(to,cost));
  }
} info[100000];
int hoge[100000];

void bfs(const int& st, const int& V){
  fill_n( hoge, V, INF);
  queue< int > que;
  que.push(st);
  hoge[st] = 0;
  while(!que.empty()){
    int p = que.front();
    que.pop();
    for(int i = 0 ; i < info[p].size() ; i++){
      int cost = info[p][i].second;
      int to = info[p][i].first;
      if( cost + hoge[p] < hoge[to]){
        que.push(to);
        hoge[to] = cost + hoge[p];
      }
    }
  }
}

int main(){
  int N;
  scanf("%d", &N);
  for(int i = 0; i < N; i++){
    int u, k;
    scanf("%d %d", &u, &k);
    while(k--){
      int v, c;
      scanf("%d %d", &v, &c);
      info[u].add_edge( v, c);
    }
  }
  bfs(0, N);
  for(int i = 0 ; i < N ; i++ ){
    printf("%d %d\n", i, hoge[i]);
  }
}

C++: #include<iostream>
#include<queue>
#include<algorithm>

using namespace std;

static const int MAX = 10000;
static const int UNVISITED = 0;
static const int VISITING = 1;
static const int VISITED = 2;

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


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

void Dijkstra() {
   
   priority_queue<pair<int, int> > PQ;
   
   int d[MAX], s[MAX];
   for( int i = 0; i < n; i++) {
    	d[i] = INFTY;
       	s[i] = UNVISITED;
    }

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

    while( !PQ.empty() ) {
       	pair<int, int > f = PQ.top(); PQ.pop();
       	int u = f.second;
       	s[u] = VISITED;
        
        if ( d[u] < f.first * (-1) ) continue;

        for( int j = 0; j < adj[u].size(); j++ ) {
        	int v = adj[u][j].first;
        	if( s[v] != VISITED ) {
        		if( d[v] > d[u] + adj[u][j].second ){
        			d[v] = d[u] + adj[u][j].second;
        			PQ.push(make_pair((-1) * d[v], v ));
        		}
        		
        	}
        }

    }

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


int main() {
      
   int u, k, v, c;

   cin >> n;
   for( int i = 0; i < n; i++) {
   	cin >> u >> k;
   	while( k-- ) {
   		cin >> v >> c;
   		adj[u].push_back( make_pair(v, c));
   	}
   }

    Dijkstra() ;

   return 0;
}

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

using size_t = std::size_t;

template<class id_type>
class Graph{
public:
  using vertex_type = size_t;
  struct Edge{
    vertex_type to;
    id_type id;
  };

  struct Edge_Pair{
    vertex_type from;
    vertex_type to;
    id_type id;
  };
private:
  std::vector<vertex_type> ver;
  std::vector<Edge_Pair> edges;
  std::vector<std::vector<Edge>> G;
  std::vector<std::vector<Edge>> rG;
public:
  Graph(size_t sz) : ver(sz) , G(sz) , rG(sz){
    for(size_t i = 0;i < ver.size();i++) ver[i] = i;
  }

  const std::vector<vertex_type>& V() const{
    return ver;
  }

  const std::vector<Edge_Pair>& E() const{
    return edges;
  }

  void add_edge(const Edge_Pair& e){
    edges.push_back(e);
    G[e.from].push_back({e.to,e.id});
    rG[e.to].push_back({e.from,e.id});
  }

  void add_edge(vertex_type from,vertex_type to,id_type id){
    add_edge({from,to,id});
  }

  Graph operator+=(const Edge_Pair& e){
    add_edge(e);
    return *this;
  }


  const std::vector<Edge>& delta_p(vertex_type v) const{
    return G[v];
  }

  const std::vector<Edge>& delta_m(vertex_type v) const{
    return rG[v];
  }

  const std::vector<Edge>& operator[](vertex_type v) const{
    return this->delta_p(v);
  }
};

#include <set>
#include <queue>
#include <functional>

template<class dist_type,class id_type>
std::vector<dist_type> dijkstra(const Graph<id_type>& g,std::function<dist_type(id_type)> cost,size_t s,dist_type init,dist_type INF){
    using vt = typename Graph<id_type>::vertex_type;
    using P = std::pair<dist_type,vt>;
    std::vector<dist_type> dist(g.V().size(),INF);
    dist[s] = init;

    std::priority_queue<P,std::vector<P>,std::greater<P>> que;

    que.push({dist[s],s});

    while(!que.empty()){
      vt v = que.top().second;
      dist_type d = que.top().first;
      que.pop();
      if(dist[v] < d) continue;
      for(const auto & e : g.delta_p(v)){
        if(dist[e.to] > dist[v] + cost(e.id)){
          dist[e.to] = dist[v] + cost(e.id);
          que.push({dist[e.to],e.to});
        }
      }
    }

    return dist;
}

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main(){
  int n;
  cin >> n;
  Graph<size_t> g(n);
  vector<i64> cost;
  for(int i = 0;i < n;i++){
    size_t u,t;
    cin >> u >> t;
    for(int j = 0;j < t;j++){
      size_t v;
      i64 c;
      cin >> v >> c;
      g.add_edge(u,v,cost.size());
      cost.push_back(c);
    }
  }

  auto res = dijkstra<i64,size_t>(g,[&](size_t id)->i64{return cost[id];},0UL,0LL,(i64)1e9);
  for(int i = 0;i < n;i++){
    cout << i << " " << res[i] << endl;
  }
}