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++: #include <bits/stdc++.h>
using namespace std;

template<typename T> struct Graph {
  struct Edge { int to; T cost; };
  vector<int> prev;
  vector<vector<Edge>> g;
  Graph(int n) : prev(n, -1), g(n) {}

  void addEdge(int u, int v, T w) {
    g[u].push_back({v, w});
    //g[v].push_back({u, w});
  }
  vector<T> dijkstra(int s) {
    vector<T> dist(g.size(), -1);
    using Node = pair<T, int>;
    priority_queue<Node, vector<Node>, greater<Node>> pq;
    pq.push({dist[s] = 0, s});

    while (!pq.empty()) {
      auto d = pq.top().first;
      auto u = pq.top().second;
      pq.pop();
      if (dist[u] < d) continue;
      for (auto&& v : g[u]) {
        if (dist[v.to] < 0 || dist[v.to] > dist[u] + v.cost) {
          dist[v.to] = dist[u] + v.cost;
          prev[v.to] = u;
          pq.push({dist[v.to], v.to});
        }
      }
    }
    return dist;
  }
  vector<int> getPath(int t) {
    vector<int> path;
    for (; t != -1; t = prev[t]) path.push_back(t);
    reverse(begin(path), end(path));
    return path;
  }
};

int main() {
  int n; cin >> n;
  Graph<int> g(n);
  for (int i = 0; i < n; ++i) {
    int u, k; cin >> u >> k;
    for (int j = 0; j < k; ++j) {
      int v, c; cin >> v >> c;
      g.addEdge(u, v, c);
    }
  }
  vector<int> d = g.dijkstra(0);
  for (int i = 0; i < n; ++i) {
    cout << i << ' ' << d[i] << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<unordered_set>
#define N 105
#define UNDEFINED -1
static const int INF = (1<<21);

int n;
int u, k, v, c;
int G[N][N];
int distance[N], hasVisited[N];


void dijkstra(int s) {
    int minv;
    distance[s] = 0;
    while(true) {
        minv = INF;
        int u = UNDEFINED;
        for (int i = 0; i < n; ++i) {
            if(minv > distance[i] && hasVisited[i] != 1) {
                u = i;
                minv = distance[i];
            }
        }
        if(u == UNDEFINED) break;
        hasVisited[u] = 1;
        for (int v = 0; v < n; ++v) {
            if(distance[v] > distance[u] + G[u][v]) {
                distance[v] = distance[u] + G[u][v];
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%i %i\n", i, distance[i]);
    }
}

int main() {
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            G[i][j] = INF;
        }
        distance[i] = INF;
        hasVisited[i] = 0;
    }

    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        std::cin >> u >> k;
        for (int j = 0; j < k; ++j) {
                std::cin >> v >> c;
                G[u][v] = c;
            }
        }

    dijkstra(0);

    return 0;
}

C++: #include <iostream>
#include <vector>

using namespace std;

int n;
vector<int> g[100];
vector<int> w[100];
int d[100];
char color[100];

void dijkstra() {
    d[0] = 0;
    color[0] = 'b';

    for (int k = 1; k < n; ++k) {
        int next;
        int mine = INT_MAX;
        for (int i = 0; i < n; ++i) {
            if (color[i] == 'b') {
                for (int j = 0; j < g[i].size(); ++j) {
                    if (d[i] + w[i].at(j) <= d[g[i].at(j)] && color[g[i].at(j)] == 'w') {
                        d[g[i].at(j)] = d[i] + w[i].at(j);
                        if (d[g[i].at(j)] <= mine) {
                            next = g[i].at(j);
                            mine = d[next];
                        }
                    }
                }
            }
        }
        color[next] = 'b';
        d[next] = mine;
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int u;
        int k;
        cin >> u >> k;
        int v, c;
        for (int j = 0; j < k; ++j) {
            cin >> v >> c;
            g[u].push_back(v);
            w[u].push_back(c);
        }
    }
    for (int m = 0; m < n; ++m) {
        color[m] = 'w';
        d[m] = INT_MAX;
    }

    dijkstra();

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

    return 0;
}

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

const int INF = 0xfffffff;
const int MAX = 10000;

struct Edge {
	bool operator < (const Edge& e)const {
		return c > e.c;
	}
	int v;
	int c;
};

int main() {
	int n;
	vector<Edge> graph[MAX];
	priority_queue<Edge> q;
	int table[MAX];
	bool check[MAX];

	cin >> n;
	for (int i = 0; i < n; i++) {
		table[i] = INF;
		check[i] = false;
	}

	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			Edge e;
			cin >> e.v >> e.c;
			graph[u].push_back(e);
		}
	}

	int u = 0;
	table[0] = 0;
	while (true) {
		check[u] = true;

		for (int i = 0; i < graph[u].size(); i++) {
			int v = graph[u][i].v;
			int c = graph[u][i].c;
			if (table[v] > c + table[u]) {
				table[v] = c + table[u];
				Edge e;
				e.v = v;
				e.c = table[v];
				q.push(e);
			}
		}
		if (check[q.top().v])break;
		u = q.top().v; q.pop();
	}

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

	return 0;
}

C++: #include <iostream>
#pragma warning(disable:4996)
using namespace std;
const int maxn = 100 + 10;
const int maxv = 10000 + 10;
const int INF = 1 << 21;
int n;
int E;
typedef struct{
	int from, to, cost;
}Edge;

Edge e[maxv];
int d[maxn];
void bellman_ford(int s){
	fill(d, d + n, INF);
	d[s] = 0;
	while (true)	{
		bool bUpdate = false;
		for (int i = 0; i<E; i++)	{
			Edge es = e[i];
			if (d[es.from] != INF&&d[es.to]>d[es.from] + es.cost)		{
				d[es.to] = d[es.from] + es.cost;
				bUpdate = true;
			}
		}
		if (!bUpdate) break;
	}
	for (int i = 0; i<n; i++) printf("%d %d\n", i, d[i]);
}

int main(){
	scanf("%d", &n);
	int id, c;
	E = 0;
	for (int i = 0; i<n; i++){
		scanf("%d%d", &id, &c);
		while (c--){
			scanf("%d%d", &e[E].to, &e[E].cost);
			e[E].from = id;
			E++;
		}
	}
	bellman_ford(0);
	return 0;
}