Go: package main

import (
	"fmt"
	"container/heap"
)

type Node struct {
	Id int
	Dis int
}

type PriorityQueue []*Node

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dis < pq[j].Dis
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(*Node))
}

func (pq *PriorityQueue) Pop() interface{} {
	n := len(*pq)
	pop := (*pq)[n-1]
	*pq = (*pq)[0:n-1]
	return pop
}

func main() {
	var n int
	fmt.Scan(&n)

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
			fmt.Scan(&c[u][j])
		}

		if u == 0 {
			d[u] = 0
		} else {
			d[u] = 1 << 30
		}
		pq.Push(&Node{u, d[u]})
	}
	heap.Init(&pq)

	for pq.Len() > 0 {
		node := heap.Pop(&pq).(*Node)
		for i := 0; i < len(g[node.Id]); i++ {
			nextId := g[node.Id][i]
			nextDis := node.Dis + c[node.Id][i]
			if nextDis < d[nextId] {
				d[nextId] = nextDis
				heap.Push(&pq, &Node{nextId, nextDis})
			}
		}
	}

	for i := 0; i < n; i++ {
		fmt.Println(i, d[i])
	}
}

C++: //Single Source Shortest Path I
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

static const int N = 100;
static const int WHITE = 0;
static const int BLACK = 1;
//int colors[N], d[N];
//
//void dijkstra(vector<vector<int>> &W, int n) {
//    int u, mind;
//    for(int i = 0; i < n; i++) {
//        colors[i] = WHITE;
//        d[i] = INT_MAX;
//    }
//    d[0] = 0;
//    while(1) {
//        u = -1;
//        mind = INT_MAX;
//        for(int i = 0; i < n; i++) {
//            if(colors[i] == WHITE && d[i] < mind) {
//                u = i;
//                mind = d[i];
//            }
//        }
//        if(u == -1) break;
//        colors[u] = BLACK;
//        for(int i = 0; i < n; i++) {
//            if(W[u][i] != -1) {
//                d[i] = min(d[i], mind + W[u][i]);
//            }
//        }
//    }
//}
int d[N];

void dijkstra(vector<vector<int>> &W, int n) {
    int colors[n];
    for(int i=0; i<n; i++) {
        colors[i] = WHITE;
        d[i] = INT_MAX;
    }
    
    d[0] = 0;

    while(1) {
        int u = -1;
        int min_distance = INT_MAX;
        for(int i=0; i<n; i++) {
            if(colors[i] == BLACK) continue;
            if(d[i] < min_distance) {
                u = i;
                min_distance = d[i];
            }
        }
        if(u == -1) break;

        colors[u] = BLACK;
        for(int i=0; i<n; i++) {
            if(colors[i] == BLACK) continue;
            if(W[u][i] == -1) continue;
            d[i] = min(d[i], d[u] + W[u][i]);
        }
    }
}

int main() {
    int n;
    int u, k, v, c;
    cin >> n;
    vector<vector<int>> W(n, vector<int>(n));
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            W[i][j] = -1;
    for(int i = 0; i < n; i++) {
        cin >> u >> k;
        for(int j = 0; j < k; j++) {
            cin >> v >> c;
            W[u][v] = c;
        }
    }

    dijkstra(W, n);

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

C++: #include<iostream>

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

void dijkstra() {
    int minv;
    int d[MAX], color[MAX];
    
    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[i] = WHITE;
    }
    
    d[0] = 0;
    color[0] = GRAY;
    
    while (1) {
        minv = INFTY;
        int u = -1;
        
        for (int i = 0; i < n; i++) {
            if (minv > d[i] && color[i] != BLACK) {
                u = i;
                minv = d[i];
            }
        }
        
        if (u == -1) {
            break;
        }
        
        color[u] = BLACK;
        
        for (int v = 0; v < n; v++) {
            if (color[v] != BLACK && M[u][v] != INFTY) {
                if (d[v] > d[u] + M[u][v]) {
                    d[v] = d[u] + M[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}

int main() {
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            M[i][j] = INFTY;
        }
    }
    
    int k, c, u, v;
    
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        
        for (int j = 0; j < k; j++) {
            cin >> v >> c;
            
            M[u][v] = c;
        }
    }
    
    dijkstra();
    
    return 0;
}

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

typedef struct NODE {
    int id;
    int degree;
    int min_cost;
    bool done;
    vector<int> adj_n;
    vector<int> cost_to_n;
} node;

node **nodes;
int n;

node *gen_node(int id, int degree, vector<int> adj_n, vector<int> cost_to_n) {
    node *p = (node *)malloc(sizeof(node));
    p->id = id;
    p->degree = degree;
    if (id != 0) {
        p->min_cost = 100010;
    } else {
        p->min_cost = 0;
    }

    p->done = false;
    p->adj_n = adj_n;
    p->cost_to_n = cost_to_n;
    return p;
}

void solve() {
    for (int i = 0; i < n; i++) {
        node *src = (node *)malloc(sizeof(node));
        src = nodes[i];
        for (int j = 0; j < src->degree; j++) {
            node *dst = (node *)malloc(sizeof(node));
            dst = nodes[src->adj_n[j]];

            // 最小コストの更新
            //cout << "src: " << src->id << " dst: " << dst->id;
            //cout << " dst's min cost: " << dst->min_cost << " src's cost to dst: " << src->min_cost + src->cost_to_n[j] << endl;
            dst->min_cost = min(dst->min_cost, src->min_cost + src->cost_to_n[j]);

            // // dstの隣接nodeからsrcを消す処理
            // auto itr = find(dst->adj_n.begin(), dst->adj_n.end(), src->id);
            // int erase_index = itr - dst->adj_n.begin();
            // dst->degree--;
            // dst->adj_n.erase(dst->adj_n.begin() + erase_index);
            // dst->cost_to_n.erase(dst->cost_to_n.begin() + erase_index);
        }
    }
}

void print_node() {
    for (int i = 0; i < n; i++) {
        cout << nodes[i]->id << " " << nodes[i]->min_cost << endl;
    }
}

int main() {
    int u, k;
    cin >> n;

    nodes = (node **)malloc(sizeof(node) * n);

    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        vector<int> adj_n;
        vector<int> cost_to_n;

        int node_tmp;
        int cost_tmp;
        for (int j = 0; j < k; j++) {
            cin >> node_tmp >> cost_tmp;
            adj_n.push_back(node_tmp);
            cost_to_n.push_back(cost_tmp);
        }
        node *p = gen_node(u, k, adj_n, cost_to_n);
        nodes[u] = p;
    }

    solve();
    solve();

    print_node();

    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
struct edge {int from, to, cost;};
const long long INF = 1000000000;
void bellman_ford(std::vector<edge> & es, std::vector<int> & d, int E, int V, int s) {
  for(int i=0;i<V;i++) d[i] = INF;
  d[s] = 0;
  while(true) {
    bool update = false;
    for(int i=0;i<E;i++) {
      edge e = es[i];
      if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
        update = true;
      }
    }
    if(!update) break;
  }
}
 
int main() {
  int n;
  cin >> n;
  vector<edge> e;
  for(int i=0;i<n;i++) {
    int u, k;
    cin >> u >> k;
    for(int j=0;j<k;j++) {
      int vi, ci;
      cin >> vi >> ci;
      edge ei = {u, vi, ci};
      e.push_back(ei);
    }
  }
  vector<int> d(n);
  bellman_ford(e, d, e.size(), n, 0);
  for(int i=0;i<n;i++) {
    cout << i << " " << d[i] << endl;
  }

}