Go: package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	"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)

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

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			sc.Scan()
			g[u][j], _ = strconv.Atoi(sc.Text())
			sc.Scan()
			c[u][j], _ = strconv.Atoi(sc.Text())
		}

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

	wr := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		wr.WriteString(strconv.Itoa(i))
		wr.WriteString(" ")
		wr.WriteString(strconv.Itoa(d[i]))
		wr.WriteString("\n")
	}
	wr.Flush()
}

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

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

int n;
vector<pair<int, int> > adj[MAX]; // 重み付き有向グラフの隣接リスト表現

void dijkstra() {
    priority_queue<pair<int, int> > PQ;
    int color[MAX];
    int d[MAX];
    for (int i=0; i<n; i++) {
        d[i] = INFTY;
        color[i] = WHITE;
    }
    
    d[0] = 0;
    PQ.push(make_pair(0, 0));
    color[0] = GRAY;
    
    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 j=0; j<adj[u].size(); j++) {
            int v = adj[u][j].first;
            if (color[v] == BLACK) continue;
            if (d[v] > d[u] + adj[u][j].second) {
                d[v] =  d[u] + adj[u][j].second
                // priority_queueはデフォルトで大きい値を優先するため-1をかける
                PQ.push(make_pair(d[v]*(-1), v));
                color[v] = GRAY;
            }
        }
    }
    
    for (int i=0; i<n; i++) {
        printf("%d %d\n", i, d[i]);
    }
}

int main() {
    int k, u, v, c;
    
    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);
            adj[u].push_back(make_pair(v, c));
        }
    }
    
    dijkstra();
    
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define Vi vector<int>
#define FOR(i,s,e) for (int i=s; i<e; i++)
#define ITER(v) v.begin(), v.end()

constexpr int N_MAX = 10000;
constexpr int INF   = 1<<30;

using IPAIR = pair<int, int>;

vector<IPAIR> weight[N_MAX];
int dis[N_MAX];

void set_shortest_distance(const int n) {
    FOR(i,0,n) {
        dis[i] = INF;
    }

    bool ismember[n] = { false };

    priority_queue<IPAIR, vector<IPAIR>, greater<IPAIR>> pq;
    pq.push(make_pair(0, 0));

    while (!pq.empty()) {
        IPAIR top = pq.top(); pq.pop();
        const int top_i = top.second;
        if (ismember[top_i]) { continue; }
        ismember[top_i] = true;
        const int top_d = top.first;
        dis[top_i] = top_d;
        for (const IPAIR& next : weight[top_i]) {
            const int next_i = next.second;
            if (ismember[next_i]) { continue; }
            const int next_w = next.first;
            const int d = top_d + next_w;
            pq.push(make_pair(d, next_i));
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    int u, k, v, c;
    FOR(i,0,n) {
        cin >> u >> k;
        FOR(j,0,k) {
            cin >> v >> c;
            weight[u].push_back(make_pair(c,v));
        }
    }

    set_shortest_distance(n);

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

    return 0;
}