Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

var infty = 1000000000

type DirectedGraphNodeID int

type DirectedGraphNode struct {
	key         DirectedGraphNodeID
	adjacents   []*DirectedGraphNode
	costs       []int
	distance    int
	predecessor *DirectedGraphNode
}

func newDirectedGraph(nNodes int) *DirectedGraph {
	graph := DirectedGraph{}
	graph.nodes = make([]*DirectedGraphNode, nNodes)
	for i := 0; i < nNodes; i++ {
		node := DirectedGraphNode{}
		node.key = DirectedGraphNodeID(i)
		node.distance = infty
		graph.nodes[i] = &node
	}
	return &graph
}

type DirectedGraph struct {
	nodes []*DirectedGraphNode
}

func (g *DirectedGraph) setAdjacency(i, j DirectedGraphNodeID, cost int) {
	g.nodes[i].adjacents = append(g.nodes[i].adjacents, g.nodes[j])
	g.nodes[i].costs = append(g.nodes[i].costs, cost)
}

func (g *DirectedGraph) print() {
	for i := 0; i < len(g.nodes); i++ {
		node := g.nodes[i]
		key := node.key
		strings := []string{strconv.Itoa(int(key)), strconv.Itoa(node.distance)}
		for j := 0; j < len(node.adjacents); j++ {
			nodeJ := fmt.Sprintf("(%v, %v)", node.adjacents[j].key, node.costs[j])
			strings = append(strings, nodeJ)
		}
		fmt.Printf("%v\n", strings)
	}
}

func (g *DirectedGraph) relaxEdge(l, r *DirectedGraphNode, w int) {
	if r.distance > l.distance+w {
		// fmt.Printf("%v -> %v, %v\n", l.key, r.key, l.distance+w)
		r.distance = l.distance + w
		r.predecessor = l
	}
}

func main() {
	scanner.Split(bufio.ScanWords)

	nNodes := nextInt()
	graph := newDirectedGraph(nNodes)

	for i := 0; i < nNodes; i++ {
		iNode := DirectedGraphNodeID(nextInt())
		nAdjacent := nextInt()
		for j := 0; j < nAdjacent; j++ {
			jNode := DirectedGraphNodeID(nextInt())
			cost := nextInt()
			graph.setAdjacency(iNode, jNode, cost)
		}
	}

	graph.nodes[0].distance = 0
	for iNode := 0; iNode < nNodes; iNode++ {
		for iLeft := 0; iLeft < len(graph.nodes); iLeft++ {
			nodeLeft := graph.nodes[iLeft]
			for iRight := 0; iRight < len(nodeLeft.adjacents); iRight++ {
				nodeRight := nodeLeft.adjacents[iRight]
				cost := nodeLeft.costs[iRight]
				graph.relaxEdge(nodeLeft, nodeRight, cost)
			}
		}
	}

	// graph.print()

	for iNode := 0; iNode < len(graph.nodes); iNode++ {
		node := graph.nodes[iNode]
		fmt.Println(node.key, node.distance)
	}
}

C++: // Problem name: Single Source Shortest Path I
// Written by: by_sknight
// Date: 2019/4/27
#include <bits/stdc++.h>
using namespace std;
#define MAX 100
#define INFTY INT_MAX

int n, G[MAX][MAX];

int s3p(int x) {
    int color[MAX], d[MAX];
    for (int i = 0; i < n; i++) {
        color[i] = 0;
        d[i] = INFTY;
    }
    d[0] = 0;
    while (1) {
        int u = -1, minv = INFTY;
        for (int i = 0; i < n; i++) {
            if (color[i] != 1 && d[i] < minv) {
                minv = d[i];
                u = i;
            }
        }
        if (u == x)
            return minv;
        color[u] = 1;
        for (int v = 0; v < n; v++) {
            if (color[v] != 1 && G[u][v] != INFTY) {
                if (d[u] + G[u][v] < d[v])
                    d[v] = d[u] + G[u][v];
            }
        }
    }
}

int main(void) {
    int k, v, c;
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            G[i][j] = INFTY;
        }
    }
    for (int i = 0; i < n; i++) {
        cin >> k >> k;
        while (k--) {
            cin >> v >> c;
            G[i][v] = c;
        }
    }

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

C++: #include <bits/stdc++.h>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
#define RREP(i, a, b) for(int i = (a); i >= (b); i--)
#define pq priority_queue
#define P pair<int, int>
#define P2 pair<int, P>
#define P3 pair<int, P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF = 1e9, MOD = 1e9+7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
const int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
const ld PI = abs(acos(-1));
const int sqrtN = 512;
const int logN = 32;
const ll LINF=1e18;

template<typename T>
struct Dijkstra{
	struct edge{
		int to;
		T cost;
	};
	const T INF;
	vector<vector<edge>> g;
	vector<T> min_cost;
	
	Dijkstra(int n) : INF(numeric_limits<T>::max() - numeric_limits<T>::max()/10){
		g.resize(n);
	}
	
	void add_edge(int from, int to, T cost){
		g[from].push_back(edge{to, cost});
	}
	
	vector<T> dijkstra(int s){
		min_cost.assign(g.size(), INF); min_cost[s] = 0;
		pq<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> qu;
		qu.push({0, s});
		
		while(!qu.empty()){
			auto p = qu.top(); qu.pop();
			
			for(auto e:g[p.second]){
				if(p.first + e.cost >= min_cost[e.to]) continue;
				min_cost[e.to] = p.first + e.cost;
				qu.push({min_cost[e.to], e.to});
			}
		}
		
		return min_cost;
	}
};


int main(){
	int n; cin >> n;
	Dijkstra<ll> dijk(n);
	for(int i = 0; i < n; i++){
		int k; cin >> k >> k;
		
		for(int j = 0; j < k; j++){
			int a, b; cin >> a >> b;
			dijk.add_edge(i, a, (ll)b);
			dijk.add_edge(a, i, (ll)b);
		}
	}
	
	vector<ll> min_cost = dijk.dijkstra(0);
	for(int i = 0; i < n; i++) cout << i << " " << min_cost[i] << endl;
	return 0;
}

C++: #include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;

struct node {
	int id;
	int cost;
	node(int i, int c){
		this->id = i;
		this->cost = c;
	}
	bool operator<(node c) const {
		return this->cost > c.cost;
	}
};

int main() {
	int n;
	scanf("%d", &n);
	
	int c[n];
	int w[n][n];
	for(int i = 0; i < n; i++){
		int u, k;
		scanf("%d %d", &u, &k);
		
		c[u] = u ? INT_MAX : 0;
		for(int j = 0; j < n; j++){
			w[u][j] = -1;
		}
		while(k--){
			int v, c;
			scanf("%d %d", &v, &c);
			w[u][v] = c;
		}
	}
	
	priority_queue<node> q;
	q.push(*new node(0, 0));
	while(q.size()){
		int i = q.top().id;
		int ca = q.top().cost;
		q.pop();
		
		for(int j = 0; j < n; j++){
			if(w[i][j] != -1 && c[j] > w[i][j] + ca){
				c[j] = w[i][j] + ca;
				q.push(*new node(j, c[j]));
			}
		}
	}
	
	for(int i = 0; i < n; i++){
		printf("%d %d\n", i, c[i]);
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
int64_t INF = (1 << 20);
int64_t N, MAXN = 10010;
vector< vector < pair<int64_t, int64_t> > > Edges(MAXN);

void dijkstra()
{
  priority_queue<pair<int64_t, int64_t>, vector<pair<int64_t, int64_t> >, greater<pair<int64_t, int64_t > > > PQ;
  vector<int64_t> Color(MAXN, 0), D(MAXN, INF); // 各点を無限大にする。

  D.at(0) = 0; // 始点を0とする。
  PQ.push(make_pair(0, 0));
  Color.at(0) = 1; // グレーの状態に

  while (!PQ.empty())
  {
    pair<int64_t, int64_t> f = PQ.top();
    PQ.pop();
    int64_t u = f.second; // 未決定の中で、最短経路の頂点
    Color.at(u) = 2;      // 決定済とする
    if (D.at(u) < f.first)
      continue;
    for (int i = 0; i < Edges.at(u).size(); i++)
    {
      int64_t v = Edges.at(u).at(i).first; // uからの辺の終点
      if (Color.at(v) == 2)
        continue;
      if (D.at(v) > D.at(u) + Edges.at(u).at(i).second) // uを経由した場合の距離
      {
        D.at(v) = D.at(u) + Edges.at(u).at(i).second;
        PQ.push(make_pair(D.at(v), v)); // 頂点vの暫定での距離、頂点vをペアにする
        Color.at(v) = 1;                // グレーにする
      }
    }
  }
  for (int i = 0; i < N; i++)
    cout << i << ' ' << (D.at(i) == INF ? -1 : D.at(i)) << endl;
}

int main()
{
  cin >> N;
  int k, u, v, c;
  for (int i = 0; i < N; i++)
  {
    cin >> u >> k;
    for (int j = 0; j < k; j++)
    {
      cin >> v >> c;
      Edges.at(u).push_back(make_pair(v, c));
    }
  }

  dijkstra();
}