Go: package main

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

const (
	white int = iota
	gray
	black
)

type node struct {
	id     int
	parent int
	edge   []int
	weight []int
	color  int
}

type graph struct {
	nodes    []node
	distance []int
}

var infty = 1 << 32
var null = -1

func constructgraph() *graph {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)

	g := &graph{make([]node, n), make([]int, n)}

	for i := 0; i < n; i++ {
		id := nextInt(sc)
		edges := nextInt(sc)
		n := node{}
		n.id = id
		n.edge = make([]int, edges)
		n.weight = make([]int, edges)
		n.color = white
		for j := 0; j < edges; j++ {
			to := nextInt(sc)
			w := nextInt(sc)
			n.edge[j] = to
			n.weight[j] = w
		}
		g.nodes[id] = n
	}
	return g
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func (g *graph) preparedijkstra(s int) {
	for i := 0; i < len(g.nodes); i++ {
		g.nodes[i].color = white
		g.nodes[i].parent = null
		g.distance[i] = infty
	}
	g.distance[s] = 0
}

func (g *graph) dijkstra(s int) []int {
	g.preparedijkstra(s)

	for {
		var u int
		mincost := infty
		for i, d := range g.distance {
			if g.nodes[i].color != black && mincost > d {
				mincost = d
				u = i
			}
		}

		if mincost == infty {
			break
		}

		g.nodes[u].color = black

		for i, e := range g.nodes[u].edge {
			if g.nodes[e].color != black {
				if g.distance[e] > g.distance[u]+g.nodes[u].weight[i] {
					g.distance[e] = g.distance[u] + g.nodes[u].weight[i]
					g.nodes[e].parent = u
					g.nodes[e].color = gray
				}
			}
		}
	}
	return g.distance
}

func printShortestPath(d []int) {
	for i, v := range d {
		fmt.Printf("%d %d\n", i, v)
	}
}

func main() {
	g := constructgraph()
	d := g.dijkstra(0)
	printShortestPath(d)
}

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