Go: package main

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

const (
	MAX_N      = 100
	MAX_WEIGHT = 100000
)

type Edge struct {
	start  int
	end    int
	weight int
}

type ShortestInfo struct {
	edges    []Edge
	shortest int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	shortestList := make([]ShortestInfo, n)
	for i := 1; i < n; i++ {
		shortestList[i] = ShortestInfo{edges: []Edge{}, shortest: MAX_N*MAX_WEIGHT + 1}
	}

	adjacentMatrix, err := createAdjacentMatrix(n, sc)
	if err != nil {
		panic(err)
	}

	sssp([]int{1}, shortestList, adjacentMatrix)
	for _, v := range shortestList {
		fmt.Printf("%d %d\n", v.getEnd()-1, v.shortest)
	}
}

func (si ShortestInfo) getEnd() int {
	if len(si.edges) == 0 {
		return 1
	} else {
		return si.edges[len(si.edges)-1].end
	}
}

func createAdjacentMatrix(n int, sc *bufio.Scanner) ([][]int, error) {
	adjacentMatrix := make([][]int, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		adjacentMatrix[id] = make([]int, n)
		for j := 0; j < n; j++ {
			adjacentMatrix[id][j] = -1
		}
		vertexNum, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		for j := 0; j < vertexNum; j++ {
			v, err := nextInt(sc)
			if err != nil {
				return nil, err
			}
			c, err := nextInt(sc)
			if err != nil {
				return nil, err
			}
			adjacentMatrix[id][v] = c
		}
	}
	return adjacentMatrix, nil
}

func sssp(nodeStack []int, shortestList []ShortestInfo, adjacentMatrix [][]int) {
	for len(nodeStack) > 0 {
		currentNode := nodeStack[0]
		nodeStack = nodeStack[1:]
		currentShortest := getShortest(currentNode, shortestList)
		adjacents := findAdjacents(currentNode, adjacentMatrix)
		for i := 0; i < len(adjacents); i++ {
			adj := adjacents[i]
			if currentShortest.shortest+adj.weight < getShortest(adj.end, shortestList).shortest {
				setShortest(adj.end, adj, currentShortest, shortestList)
				nodeStack = append(nodeStack, adj.end)
			}
		}
	}
}

func getShortest(node int, shortestList []ShortestInfo) ShortestInfo {
	return shortestList[node-1]
}

func setShortest(node int, edge Edge, currentShortest ShortestInfo, shortestList []ShortestInfo) {
	newEdges := make([]Edge, len(currentShortest.edges)+1)
	for i := 0; i < len(newEdges)-1; i++ {
		newEdges[i] = currentShortest.edges[i]
	}
	newEdges[len(newEdges)-1] = edge
	shortestInfo := ShortestInfo{edges: newEdges, shortest: currentShortest.shortest + edge.weight}
	shortestList[node-1] = shortestInfo
}

func findAdjacents(currentNode int, adjacentMatrix [][]int) []Edge {
	adjacents := adjacentMatrix[currentNode-1]
	edges := []Edge{}
	for i, v := range adjacents {
		if v > 0 {
			edges = append(edges, Edge{start: currentNode, end: i + 1, weight: v})
		}
	}
	return edges
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

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

}

C++: #include <iostream>
using namespace std;
#define MAX 100
#define INFTY 1<<22
#define WHITE 0
#define GRAY 1
#define BLACK 2

int gMatrix[MAX][MAX];

void dijkstra(int n){
    // 最小の重みを記録する
    int minV;
    int weight[MAX];
    int color[MAX];
    
    for(int i = 0;i < n;++i){
        weight[i] = INFTY;
        color[i] = WHITE;
    }
    // 始点
    weight[0] = 0;
    color[0] = GRAY;
    
    while(1){
        minV = INFTY;
        // 頂点
        int u = -1;
        for(int i = 0;i < n;++i){
            if(minV > weight[i] && color[i] != BLACK){
                u = i;
                minV = weight[i];
            }
        }
        if(u == -1)break;
        color[u] = BLACK;
        
        for(int v = 0;v < n;++v){
            if(color[v] != BLACK && gMatrix[u][v] != INFTY){
                if(weight[v] > weight[u] + gMatrix[u][v]){
                    weight[v] = weight[u] + gMatrix[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }
    // 出力
    for(int i = 0;i < n;++i){
        cout << i << " " << ( weight[i] == INFTY ? -1 : weight[i] ) << endl;
    }
}

int main(){
    int n;
    cin >> n;
    
    for(int i = 0;i < n;++i){
        for(int j = 0;j < n;++j){
            gMatrix[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;
            gMatrix[u][v] = c;
        }
    }
    dijkstra(n);
    return 0;
}