Go: package main

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

func main() {
	r := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscan(r, &n)
	cs := make([]map[int]int, n) // []v_i -> c_i
	for h := 0; h < n; h++ {
		var u, k int
		fmt.Fscan(r, &u, &k)
		m := make(map[int]int)
		for i := 0; i < k; i++ {
			var v, c int
			fmt.Fscan(r, &v, &c)
			m[v] = c
		}

		cs[u] = m
	}

	q := make(map[int]int)
	q[0] = 0
	visited := make(map[int]struct{})
	out := make([]int, n)

	for len(q) > 0 {
		u := top(q)
		for uu, c := range cs[u] {
			// Consider the connection between u and uu.
			if _, ok := visited[uu]; ok {
				continue
			}
			if d, ok := q[uu]; !ok || d > q[u]+c {
				q[uu] = q[u] + c
			}
		}

		out[u] = q[u]
		delete(q, u)
		visited[u] = struct{}{}
	}

	for u, d := range out {
		fmt.Println(u, d)
	}
}

func top(q map[int]int) int {
	minu := -1
	min := -1
	for u, d := range q {
		if min < 0 || d < min {
			minu = u
			min = d
		}
	}

	return minu
}

C++: #include <stdio.h>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int dijkstra(int s) {
    int d[n], p[n];
    int color[n];
    
    for(int i=0; i<n; i++) {
        color[i] = WHITE;
        d[i] = INFTY;
        p[i] = -1;
    }
    
    d[s] = 0;
    
    while(1) {
        int u;
        int mincost = INFTY;
        for (int i=0; i<n; i++) {
            if (color[i] != BLACK && d[i] < mincost) {
                mincost = d[i];
                u = i;
            }
        }
        
        if (mincost == INFTY) break;
        
        color[u] = BLACK;
        
        for (int v=0; v<=n; v++) {
            if (color[v] != BLACK && M[u][v] != INFTY) {
                if(d[u] + M[u][v] < d[v]) {
                    d[v] = d[u] + M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }
    
    int sum = 0;
    for (int i=0; i<n; i++) {
        sum += d[i];
    }
    return sum;
}

int main() {
    scanf("%d", &n);
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            int tmp;
            scanf("%d", &tmp);
            M[i][j] = (tmp == -1) ? INFTY : tmp;
        }
    }
    
    int sum = dijkstra(0);
    printf("%d\n", sum);
    
    return 0;
}

C++: #include<bits/stdc++.h>
#define to first
#define wgt second 

using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vec;
typedef vector<vec> Graph;

Graph G(11000);
int n,d[11000];

void SPFA()
{
	bool used[11000];
	queue<int> que;
	memset(used,false,sizeof(used));
	fill(d,d+n,INT_MAX);
	d[0]=0;
	que.push(0);
	while(!que.empty())
	{
		int u=que.front();que.pop();
		for(int i=0;i<G[u].size();i++)
			if(d[G[u][i].to]>d[u]+G[u][i].wgt)
			{
				d[G[u][i].to]=d[u]+G[u][i].wgt;
				que.push(G[u][i].to);
			}
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int u,t;
		scanf("%d%d",&u,&t);
		for(int j=0;j<t;j++)
		{
			int v,w;
			scanf("%d%d",&v,&w);
			G[u].push_back(make_pair(v,w));
		}
	}
	SPFA();
	for(int i=0;i<n;i++)
		printf("%d %d\n",i,d[i]);
	return 0;
}

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

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

class Node{
public:
  int _id;
  bool _isFound;
  vector<int> _adj_index; // 隣接点のid
  vector<int> _adj_vertices;  // 隣接点との距離(重み)
  int _cost;

  void init(int id, int n){
    _id = id;
    _isFound = false;
    for(auto i = 0; i < n; i++){
      _adj_vertices.push_back(MAX);
    }
  }
};


void inputAdjList(vector<Node>& graph){
  for(auto i = 0; i < graph.size(); i++){
    int id, dim;
    cin >> id >> dim;
    graph[i].init(i, graph.size());
    for(auto j = 0; j < dim; j++){
      int vertex, distance;
      cin >> vertex >> distance;
      graph[i]._adj_index.push_back(vertex);
      graph[i]._adj_vertices[graph[i]._adj_index[j]] = distance;
    }
  }
}

void dijkstra(vector<Node>& nodes, int start){
  for(auto& node : nodes){
    node._isFound = false;
    node._cost = MAX;
  }

  nodes[start]._cost = 0;

  while(true){
//  cout << endl << "while start" << endl;
    Node *doneNode = nullptr;
    for(auto& node : nodes){
//  cout << "call for start" << node._cost << endl;
      if(node._isFound || node._cost == MAX){
//  cout << "continue" << node._cost << endl;
        continue;
      }
      if(doneNode == nullptr || node._cost < doneNode->_cost){

        doneNode = &node;
//  cout << "call" << node._cost << endl;
      }
    }
    if(doneNode == nullptr){
      break;
    }

//    cout << nodes[0]._isFound << endl;
    doneNode->_isFound = true;
//    cout << nodes[0]._isFound << endl;
    for(auto i = 0; i < doneNode->_adj_index.size(); i++){
//      cout << "i " << i << endl;
      auto nextIndex = doneNode->_adj_index[i];
      auto cost = doneNode->_cost + doneNode->_adj_vertices[doneNode->_adj_index[i]];
//    cout << endl << nextIndex << endl;
//    cout << cost << endl;
//    cout << nodes[nextIndex]._cost << endl;
      if(nodes[nextIndex]._cost == MAX || cost < nodes[nextIndex]._cost){
        nodes[nextIndex]._cost = cost;
//    cout << "called " << endl;
      }
    }
  }
}


int main(){
  int n;
  cin >> n;
  vector<Node> graph(n);

  inputAdjList(graph);
  dijkstra(graph, 0);

  for(auto g : graph){
    cout << g._id << " " << g._cost << endl;
  }

  return 0;
}

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

using namespace std;
using ll = long long;

template <class T>
struct Edge {
    int to;
    T cost;
    Edge(int to, T cost) : to(to), cost(cost){};
};

template <class T = int>
class Graph {
public:
    explicit Graph(int N = 0) : size(N) { path.resize(size); }
    void span(int u, int v, T cost = 1) { path[u].push_back(Edge<T>(v, cost)); }
    vector<Edge<T>> operator[](int v) const { return path[v]; }

    int size;
    vector<vector<Edge<T>>> path;
};

const ll INF = 1LL << 50;

template <class T>
vector<T> dijkstra(const Graph<T>& graph, int s) {
    vector<T> dist(graph.size, INF);
    dist[s] = 0;

    priority_queue<pair<int, T>, vector<pair<int, T>>, greater<pair<int, T>>> que;
    que.push(make_pair(0, s));

    while (!que.empty()) {
        int v;
        T d;
        tie(d, v) = que.top();
        que.pop();
        if (d > dist[v]) continue;

        for (const auto& e : graph[v]) {
            if (dist[e.to] <= dist[v] + e.cost) continue;
            dist[e.to] = dist[v] + e.cost;
            que.push(make_pair(dist[e.to], e.to));
        }
    }
    return dist;
}

int main() {
    int N;
    cin >> N;

    Graph<ll> graph(N);
    for (int i = 0; i < N; ++i) {
        int v, k;
        cin >> v >> k;
        for (int j = 0; j < k; ++j) {
            int sv;
            ll c;
            cin >> sv >> c;
            graph.span(v, sv, c);
        }
    }

    auto dist = dijkstra<ll>(graph, 0);
    for (int v = 0; v < N; ++v) cout << v << " " << dist[v] << endl;
    return 0;
}