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 <iostream>
#include <vector>
#include <limits>
#include <queue>

using namespace std;

struct Node {
  int label;
  int weight;

  bool operator>(const Node& other) const{
    return weight > other.weight;
  }
};

using ListGraph = vector<vector<Node>>;


const int max_num = numeric_limits<int>::max();


// priority_queueはpriorityが大きいのもから取り出す。
// デフォルトでは < (less<T>)を要素の比較に用いる。
// lessの場合要素が小さい時に入れ替える、つまりmaxHeapであり、priortyが大きいものから取り出される。

vector<int> shortest_cost(ListGraph &list_graph, int started_label) {
  vector<bool> visited_vertices(list_graph.size() ,false);
  vector<int> costs(list_graph.size(), max_num);
  priority_queue<Node, vector<Node>, greater<Node>> adjacency_costs;

  costs[started_label] = 0;
  adjacency_costs.push({started_label, costs[started_label]});

  while(!adjacency_costs.empty()) {
    Node nearest_node = adjacency_costs.top();
    adjacency_costs.pop();

    if(nearest_node.weight != costs[nearest_node.label]) {
      continue;
    }

    for(int i = 0; i < list_graph[nearest_node.label].size(); i++) {
      Node adjacency = list_graph[nearest_node.label][i];
      if(visited_vertices[adjacency.label]) {
        continue;
      }

      if(costs[nearest_node.label] + adjacency.weight < costs[adjacency.label]) {
        costs[adjacency.label] = costs[nearest_node.label] + adjacency.weight;
        adjacency_costs.push({adjacency.label, costs[adjacency.label]});
      }
    }
  }

  return costs;
}

int main() {
  int vertex_num;
  ListGraph list_graph;
  cin >> vertex_num;
  list_graph.resize(vertex_num);

  for(int i = 0; i < vertex_num; i++) {
    int label, degree;
    cin >> label >> degree;
    list_graph[i].resize(degree);

    for(int j = 0; j < degree; j++) {
      Node adjacency;
      cin >> adjacency.label >> adjacency.weight;

      list_graph[i][j] = adjacency;
    }
  }

  vector<int> costs = shortest_cost(list_graph, 0);

  for(int i = 0; i < costs.size(); i++) {
    cout << i << ' ' << costs[i] << endl;
  }
}

C++: #include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

const int N=10000;
const long INF=1000000000;

int main(){
	int n;
	vector<pair<int,long> > adj[N]; //????????????????????°???????????£??\???????????¨???
	
	//??\???
	scanf(" %d", &n);
	for(int i=0; i<n; ++i){
		int u, k;
		scanf(" %d %d", &u, &k);
		
		for(int j=0; j<k; ++j){
			int v;
			long c;
			scanf(" %d %ld", &v, &c);
			adj[u].push_back(make_pair(v,c)); //v??¨??£??\????????????????????¨??????????????????c
		} 	
	}
		
	//PriorityQueue?????¨??????Dijkstra???
	priority_queue<pair<long,int> > pq;
	
	int visit[N]={0};
	
	long cost[N];
	for(int i=0; i<N; ++i) cost[i]=INF;
	cost[0]=0; //?§?????????????????????§?§??????????	
	pq.push(make_pair(0, 0));
	visit[0]=-1; //?¨??????????
	
	while(!pq.empty()){
		pair<long,int> p=pq.top(); //pq??????????????§cost???????°?????????????????????????
		pq.pop();
		
		long u=p.second;
		visit[u]=-1; //????????????????¨???????????????????
		
		//????°??????¨???????????????????????§???????????°??????
		if(cost[u] < p.first*(-1)) continue;	
		
		//??£??\???????????????????????????
		for(int j=0; j<adj[u].size(); ++j){
			long v=adj[u][j].first; //u?????£??\????????????
			if(visit[v]==-1) continue;
			
			if(cost[v] > cost[u]+adj[u][j].second){
				cost[v] = cost[u]+adj[u][j].second;
				pq.push(make_pair(cost[v]*(-1), v));
				visit[v]=1;
			}
		}
		
	}
	
	for(int i=0; i<n; ++i)
		printf("%d %ld\n", i, (cost[i]==INF ? -1 : cost[i]));
}

C++: // ConanYu's https://vjudge.net/solution/13220749
// semon0x29a's https://vjudge.net/solution/13218148

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using pi = pair<int, int>;

const int INF = 0x3F3F3F3F;
const int maxN = 10010;

int n;
bool mark[maxN];
LL dis[maxN];
map<pi, LL> path;

void init() {
	memset(dis, 0x3F, sizeof(dis));
}

void dijkstra() {
	dis[0] = 0;
	for (int i=0; i<n; ++i) {
		int marker = 0, amin = INF;
		for (int i=0; i<n; ++i) if (!mark[i]) {
			if (dis[i] < amin) {
				amin = dis[i];
				marker = i;
			}
		}
		mark[marker] = true;
		for (int i=0; i<n; ++i) if (!mark[i]) {
			if (path.count({marker, i}))
			if (dis[i] > dis[marker] + path[{marker, i}])	
				dis[i] = dis[marker] + path[{marker, i}];
		}
	}
}

int main()
{
	init();
	
	scanf("%d", &n);
	for (int i=0; i<n; ++i) 
	{
		int u, k; scanf("%d%d", &u, &k);
		while (k--) {
			int v; LL c; scanf("%d%lld", &v, &c);
			if (path.count({u, v}))
				path[{u, v}] = min(path[{u, v}], c);
			else path[{u, v}] = c;
			path[{v, u}] = path[{u, v}];
		}
	}
	
	dijkstra();
	for (int i=0; i<n; ++i) {
		printf("%d %lld\n", i, dis[i]);
	}
}