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 <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
typedef pair<int, int> P;
#define MAX_N (105)
#define MAX_C (100010)
#define INF (MAX_N * MAX_C)
vector<P> G[MAX_N];
int dist[MAX_N];
bool arrived[MAX_N];

int main()
{
    int n;
    scanf("%d", &n);
    
    for ( int i = 0; i < n; i++ ) {
	int u, k;
	scanf("%d %d", &u, &k);
	for ( int j = 0; j < k; j++ ) {
	    int v, c;
	    scanf("%d %d", &v, &c);
	    G[u].push_back( make_pair(v, c) );
	}
    }
    
    for ( int i = 0; i < n; i++ ) {
	dist[i] = INF;
    }

    dist[0] = 0;

    while ( true ) {
	int min_dist = INF;
	int u = -1;
	for ( int i = 0; i < n; i++ ) {
	    if ( !arrived[i] ) {
		if ( min_dist > dist[i] ) {
		    min_dist = dist[i];
		    u = i;
		}
	    }
	}
	
	if ( min_dist == INF ) break;
	arrived[u] = true;

	for ( int i = 0; i < G[u].size(); i++ ) {
	    P p = G[u][i];
	    int v = p.first;
	    int c = p.second;

	    if ( !arrived[v] ) {
		dist[v] = min( dist[v], dist[u] + c );
	    }
	}
    }

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

    return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream> 
using namespace std;  
const int maxn=105;
const int INF = 0x3f3f3f3f;   
int Map[maxn][maxn]; 
int n;
int min(int x,int y)
{
	if(x<y) return x;
	else  return y;
 } 
void floyd()  
{  
    for(int k=0;k<n;k++)  
        for(int i=0;i<n;i++)  
            for(int j=0;j<n;j++)  
            Map[i][j]=min(Map[i][j],Map[i][k]+Map[k][j]);  
}  
int main()  
{   
    scanf("%d",&n);
	     for(int i = 0 ; i<n ; i++)
			for(int j = 0 ; j<n ; j++) 
				Map[i][j] = i==j?0:INF;
    for(int i=0;i<n;i++) 
    {   int a,m;
	    scanf("%d%d",&a,&m);
        for(int i=0;i<m;i++)  
        {  
            int b,w;  
            scanf("%d%d",&b,&w);  
            Map[a][b]=Map[b][a]=min(Map[a][b],w);  
        }
    }
        floyd();
        for(int i=0;i<n;i++)
        {
        printf("%d %d\n",i,Map[0][i]); 
		}  
    return 0;  
}

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

const int INF = INT_MAX;
typedef pair<int, int> P;

struct edge {int to, cost;};

/*
[input]
const vector<vector<edge>> &graph : ??\?????°??????
int s : ?§????
int g : ??????
n*/
int dijkstra(const vector<vector<edge>> &graph, int s, int g ) {
  // ????????????????±?????????????????????????
  vector<int> d(graph.size(), INF);
  // ????§?????????????????????????0????????????
  d[s] = 0;
  // ??????????????????now
  set<P> now;
  // ????§?????????????now????????\
  now.insert(P(0, s));
  
  // now????????????????????§
  while(!now.empty()) {
    // ?????¨?????????????????????pos???????´?
    int pos = now.begin()->second;
    // ?????¨??????????????????????????????????±???????????????????????????????
    if (pos == g) {
      for(int i = 0; i <= g; i++) {
        cout << i << " " << d[i] << endl;
      }
      return INF;
    }
    // now????????¢?´¢?????????????¶????
    now.erase(now.begin());
    // ?????¨??????????????¨???????????¢?´¢
    for(auto ed: graph[pos]) {
      // ??\?¶??????????????????????????????????????????¨??????????????§????????????
      // ??¨??\?¶?????????§?????¨????????????????????????????????§???????????°
      if(d[ed.to] > d[pos] + ed.cost) {
        // now????????\?¶?????????????????±????????????????????????????
        now.erase(P(d[ed.to], ed.to));
        d[ed.to] = d[pos] + ed.cost;
        now.insert(P(d[ed.to], ed.to));
      }
    }
  }
  return INF;
}
  
int main() {
  int num;
  cin >> num;
  vector<vector<edge>> graph(num, vector<edge>());
  int f, n, k, v, c;
  for(int i = 0; i < num; i++) {
    cin >> f >> k;
    for(int j = 0; j < k; j++) {
      cin >> v >> c;
      graph[f].push_back(edge{v, c});
      graph[v].push_back(edge{f, c});
    }
  }
  dijkstra(graph, 0, num - 1);
  return 0;
}

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

#define MAX_VERTEX 100
#define INF 1000000

int d[MAX_VERTEX][MAX_VERTEX];

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

  for(int i = 0; i < vertex_num; i++) {
    for(int j = 0; j < vertex_num; j++) {
      if (i == j) d[i][i] = 0;
      else d[i][j] = INF;
    }
  }

  for (int i = 0; i < vertex_num; i++) {
    int vertex, out;
    cin >> vertex >> out;
    for(int j = 0; j < out; j++) {
      int to, c;
      cin >> to >> c;
      d[vertex][to] = c;
    }
  }

  for (int k = 0; k < vertex_num; k++) {
    for (int i = 0; i < vertex_num; i++) {
      for (int j = 0; j < vertex_num; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

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

  return 0;
}

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

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
//int INF = (1<<21);

void dijkstra(void);

int n;
int M[MAX][MAX];

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

void dijkstra(){
  int minV;
  int d[MAX],color[MAX];
  int u,v;
  int i;
  for(i = 0; i < n; i++){
    d[i] = INFINITY;
    //d[i] = INF;
    color[i] = WHITE;
  }
  d[0] = 0;
  color[0] = GRAY;
  while(1){
    minV = INFINITY;
    //minV = INF;
    u = -1;
    for(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(v = 0; v < n; v++){
      if(color[v] != BLACK && M[u][v] != INFINITY){
      //if(color[v] != BLACK && M[u][v] != INF){
        if(d[v] > d[u] + M[u][v]){
          d[v] = d[u] + M[u][v];
          color[v] = GRAY;
        }
      }
    }
  }
  for(i = 0; i < n; i++){
    cout << i << " " << (d[i] == INFINITY ? -1 : d[i]) << endl;
    //cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
  }
}