Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

const NIL = -1

type Node struct {
	id     int
	weight int
}

func init() {
	sc.Split(bufio.ScanWords)
}

type NodeHeap []Node

func (h NodeHeap) Len() int           { return len(h) }
func (h NodeHeap) Less(i, j int) bool { return h[i].weight < h[j].weight }
func (h NodeHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *NodeHeap) Push(x interface{}) {
	*h = append(*h, x.(Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()

	route := make([][]Node, n)
	weight := make([]int, n)
	for i := 0; i < n; i++ {
		weight[i] = NIL
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		route[i] = make([]Node, k)
		for j := 0; j < k; j++ {
			route[u][j] = Node{id: scanInt(), weight: scanInt()}
		}
	}

	start := Node{id: 0, weight: 0}
	h := &NodeHeap{start}
	heap.Init(h)

	for h.Len() > 0 {
		node := heap.Pop(h).(Node)
		if weight[node.id] != NIL {
			continue
		}
		weight[node.id] = node.weight

		for _, nextNode := range route[node.id] {
			if weight[nextNode.id] != NIL {
				continue
			}
			nextNode.weight += node.weight
			heap.Push(h, nextNode)
		}
	}

	for i, w := range weight {
		fmt.Println(i, w)
	}
}

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

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)

#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;

static const int MAX = 100;
static const int White = 0;
static const int Gray = 1;
static const int Black = 2;


int n, M[MAX][MAX];
int d[MAX], p[MAX],color[MAX];

void dijkstra() {
	rep(i, n) {
		color[i] = White;
		d[i] = INF;
		p[i] = -1;
	}
	d[0] = 0;
	while (true) {
		int u, mincost = INF;
		rep(i, n) {
			if (color[i] != Black and d[i] < mincost) {
				u = i;
				mincost = d[i];
			}
		}
		if (mincost == INF) break;
		color[u]  = Black;
		int v;
		rep(v, n) {
			if (color[v] != Black and M[u][v] != INF) {
				if (d[u] + M[u][v] < d[v]) {
					d[v] = d[u] + M[u][v];
					p[v] = u;
					color[v] = Gray;
				}
			}
		}
	}
	rep(i, n) {
		cout << i << ' ' << d[i] << '\n';
	}
}

signed main() {
	ios::sync_with_stdio(false);
	int i, j, k;
	cin >> n;
	rep(i, n) {
		rep(j, n) {
			M[i][j] = INF;
		}
	}
	rep(i, n) {
		int u, k;
		cin >> u >> k;
		rep(j, k) {
			int c,v;
			cin >> v >> c;
			M[u][v] = c;
		}
	}
	dijkstra();
	return 0;
}