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

static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int BLACK = 1;

int n, M[MAX][MAX];

void dijkstra() {
    int u, minv;
    int color[MAX], d[MAX];
    for (int i = 0; i < n; i++) {
        color[i] = WHITE;
        d[i] = INFTY;
    }

    // 0 start
    d[0] = 0;
    while (true) {
        // choose u
        minv = INFTY;
        u = -1;
        for (int i = 0; i < n; i++)
        {
            if (color[i] != BLACK && d[i] < minv) {
                u = i;
                minv = d[i];
            }
        }

        if (u == -1) {
            break;
        }

        // move u
        color[u] = BLACK;

        // update distance
        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];
            }
        }
    }
    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 u, k, c, 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();
}

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][v]+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++){
    xin >> u >> k;
    for(int j=0;j<k;j++){
      xin >> v >>c;
      M[u][v]=c;
    }
  }
  dijkstra();

  return 0;
}

C++: #include <bits/stdc++.h>
static const int MAX = 100;
static const int INFTY = 10000000;
int V;
std::vector<std::pair<int, int> > G[MAX];

void dijkstra() {
    std::priority_queue<std::pair<int, int> > pq;
    bool visited[MAX];
    int d[MAX];
    for (int i = 0; i < V; i++) {
        visited[i] = false;
        d[i] = INFTY;
    }
    d[0] = 0;
    pq.push({0, 0}); //dist from target * -1, current node
    visited[0] = true;

    while ( !pq.empty() ) {
        std::pair<int, int> f = pq.top(); pq.pop();
        int current = f.second;
        visited[current] = true;

        if (d[current] < f.first * (-1)) continue;

        for (unsigned long i = 0; i < G[current].size(); i++) {
            int target = G[current][i].first;
            if (visited[target]) continue;
            if (d[target] > d[current] + G[current][i].second) {
                d[target] = d[current] + G[current][i].second;
                pq.push({d[target] * (-1), target});
            }
        }
    }

    for (int i = 0; i < V; i++) {
        std::cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << std::endl;
    }
}



int main()
{
    int source, target, cost, edges;
    std::scanf("%d", &V);
    for (int i = 0; i < V; i++) {
        std::scanf("%d %d", &source, &edges);
        for (int j = 0; j < edges; j++) {
            std::scanf("%d %d", &target, &cost);
            G[source].push_back({target, cost});
        }
    }
    dijkstra();
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


void Dijkstra(int s, const vector<vector<P>> &g, vector<int> &dis) {
  priority_queue<P, vector<P>, greater<P>> que; // pair = (cost, v);
  dis[s] = 0;
  que.emplace(0,s);
  while(!que.empty()) {
    P p = que.top(); que.pop();
    int now = p.second;
    if(dis[now] < p.first) continue;
    for(P np : g[now]) {
      int next = np.second;
      if(dis[next] > dis[now] + np.first) {
        dis[next] = dis[now] + np.first;
        que.emplace(dis[next], next);
      }
    }
  }
}


int main(){
    
    int n;
    cin >> n;
    V<V<P>> g(n); // pair = (cost, to);
    rep(i,n) {
        int a, k;
        cin >> a >> k;
        rep(j,k) {
            int b, v;
            cin >> b >> v;
            g[a].emplace_back(v,b);
        }
    }

    V<int> d(n, inf);
    Dijkstra(0,g,d);
    rep(i,n) {
        printf("%d %d\n", i, d[i]);
    }
}

C++: #include <bits/stdc++.h>
#define ll long long int
#define P pair<int,int>
struct edge{int to,cost;};
using namespace std;


class CompareDist
{
public:
    bool operator()(pair<int,int> n1,pair<int,int> n2) {
        return n1.second>n2.second;
    }
};

int V;
vector<vector<edge>> G;
vector<int> d;

void dijkstra(int s){
    priority_queue<P,vector<P>,CompareDist> q;
    //fill(d,d+V,INT_MAX);
    d=vector<int>(V,INT_MAX);
    d[s]=0;
    q.push(P(0,s));
    
    while(!q.empty()){
        P p=q.top();q.pop();
        int v=p.first;
        if(d[v]<p.second)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(P(e.to,d[e.to]));
            }
        }
    }
}
int main(void){
    int n,in,t,c;
    cin>>n;
    V=n;
    G.resize(n);
    d.resize(n);
    for(int i=0;i<n;i++){
        cin>>in;
        int node=in;
        cin>>in;
        for(int j=0;j<in;j++){
            cin>>t>>c;
            G[node].emplace_back((edge){t,c});
        }
        
    }
    dijkstra(0);
    for(int i=0;i<d.size();i++){
        cout<<i<<" "<<d[i]<<endl;
    }
}