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++: #include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;
 
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;
 
template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}
 
// ------------------------------------------------------------------------------------------
 
struct edge { int to, cost; };
struct P { 
   int dist, number; 
   bool operator<(const P &p) const {
      return dist < p.dist;
   }
};
 
const int INF = 1e8;
int n;
vec<vec<edge>> G;
int d[111];

void printDist() {
   rep (i, n) { printf("%d %d\n", i, d[i]); }
}
 
void dijkstra(int s) {
   fill(d, d + n, INF);
   d[s] = 0;
   priority_queue<P> Q;
   Q.push({0, s});
   while (Q.size()) {
      P p = Q.top(); Q.pop();
      int v = p.number;
      if (d[v] < p.dist) continue;
      for (int i = 0; i < G[v].size(); i++) {
         edge e = G[v][i];
         if (d[e.to] > d[v] + e.cost) {
            d[e.to] = d[v] + e.cost;
            Q.push({d[e.to], e.to});
         }
      }
      // printDist();
      // line()
   }
}
 
int main() {
   // 入力
   cin >> n;
   G = vec<vec<edge>>(n);
   rep (i, n) {
      int u, k;
      cin >> u >> k;
      rep (j, k) {
         int v, c;
         cin >> v >> c;
         G[u].push_back({v, c});
      }
   }
 
   // ダイクストラ法
   dijkstra(0);
 
   // 出力
   printDist();
 
   return 0;
}

C++: #include <stdio.h>

using namespace std;


int main(){
	int n,count=0,t,min,min_index,tmp,left_node,right_node,dist;
	scanf("%d",&n);
	int distance[n][n],P[n];

	for(int i=0;i<n;i++){
		for(int k=0;k<n;k++)distance[i][k]=10000001;
		P[i]=0;
	}
	distance[0][0] = 0;
	P[0]=1;

	for(int i=0;i<n;i++){
		scanf("%d %d",&left_node,&tmp);
		for(int k=0;k<tmp;k++){
			scanf("%d %d",&right_node,&dist);
			distance[left_node][right_node] = dist;
		}
	}

	while(count<n-1){

		min=10000001;
		for(int i=1;i<n;i++){
			if(P[i]==0&&distance[0][i]<min){
				min_index = i;
				min = distance[0][i];
			}
		}
		t = min_index;
		P[t]=1;
		count++;

		for(int i=0;i<n;i++){
			if(distance[0][i] > distance[0][t]+distance[t][i]){
				distance[0][i]=distance[0][t]+distance[t][i];
			}
		}
	}

	for(int i=0;i<n;i++){
		printf("%d %d\n",i,distance[0][i]);
	}

    return 0;
}

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

static const int MAX_NUM   = 101;
static const int NIL       = 10000001;
static const int NO_VISIT  = 0;
static const int NOW_VISIT = 1;
static const int END_VISIT = 2;

void SSSP(int *pMatrix, int num)
{
    int i;
    int mincost;
    int target;
    int lcost[MAX_NUM];
    int parent[MAX_NUM];
    int state[MAX_NUM];
    int *pList;

    for (i = 0; i < num; i++) {
        lcost[i]  = NIL;
        parent[i] = -1;
        state[i]  = NO_VISIT;
    }

    lcost[0]  = 0;
    parent[0] = 0;
    state[0]  = NOW_VISIT;

    for (;;) {
        mincost   = NIL;
        for (i = 0; i < num; i++) {
            if ((lcost[i] < mincost) && (state[i] != END_VISIT)) {
                target = i;
                mincost = lcost[i];
            }
        }
        if (mincost == NIL) {
            break;
        }

        state[target] = END_VISIT;
        pList = pMatrix + MAX_NUM * target;
        for (i = 0; i < num; i++) {
            if ((*(pList + i) + lcost[target]) < lcost[i]) {
                lcost[i]  = *(pList + i) + lcost[target];
                state[i]  = NOW_VISIT;
                parent[i] = target;
            }
        }
    }

    for (i = 0; i < num; i++) {
        printf("%d %d\n", i, lcost[i]);
    }

    return;
}

int main(void)
{
    int i, j;
    int num;
    int tmp;
    int target, elem, cost;
    int matrix[MAX_NUM][MAX_NUM];

    scanf("%d", &num);
    for (i = 0; i < num; i++) {
        for (j = 0; j < num; j++) {
            matrix[i][j] = NIL;
        }
    }

    for (i = 0; i < num; i++) {
        scanf("%d %d", &target, &tmp);
        for (j = 0; j < tmp; j++) {
            scanf("%d %d", &elem, &cost);
            matrix[target][elem] = cost;
        }
    }

    SSSP(&matrix[0][0], num);

    return 0;
}

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;

}