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 <iostream>
#include <algorithm>
using namespace std;

#define MAX_VERTEX  100
#define INF         1000000

int vertex_num;                   // ???????????°

int cost[MAX_VERTEX][MAX_VERTEX]; // ????????????cost[?§????][??????]??§?§?????????????????????????????????¨???
int d[MAX_VERTEX];                // ????????????d[u]??§?§??????¨u??????????????¢?????¨??????
bool used[MAX_VERTEX];            // ????????????????????£????????¢????±???????????????????

void Input() {
	cin >> vertex_num;

	// (a1) ??\???????????¶??§?????????

	// d??¨cost?????¨???INF
	// used????????????false
  for (int i = 0; i < vertex_num; i++) {
    d[i] = INF;
    used[i] = false;
    for (int j = 0; j < vertex_num; j++) {
      cost[i][j] = INF;
    }
  }

	for (int i = 0; i < vertex_num; i++) {
		int from, out_num;
		cin >> from >> out_num;
		for (int j = 0; j < out_num; j++) {
			int to, c;
			cin >> to >> c;
			cost[from][to] = c;
		}
	}
}

void Dijkstra() {

	// (b1) ?§????????????????
  d[0]    = 0;

	while (true) {
		// ????????????????????¨???
		int vertex = -1;

		// (b2) ????????????????????£????????¢????±??????????????????????
		// ?????????????????????????????????????????§????????¢???????°???????????????¢???
    for(int u = 0; u < vertex_num; u++) {
      if(!used[u] && (vertex == -1 || d[u] < d[vertex])) {
        vertex = u;
      }
    }

		// ??¨????????????????????????????¨?????????????????????´????????????????????????
		if (vertex == -1) {
      break;
    }

		used[vertex] = true;

		// ???????????¢????¨????????????????
    for(int u = 0; u < vertex_num; u++) {
      d[u] = min(d[u], d[vertex] + cost[vertex][u]);
    }

	}

}

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

int main() {

	Input();
	Dijkstra();
	Output();

	return 0;
}

C++: #include<cstdio>
#define INF 200001 
 
int main(){
 int u,k,C,V,A[1000][1000],D[1000][1000],n;
  scanf("%d",&n);
   for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j] = INF;
  for(int i=0;i<n;i++){
      scanf("%d %d",&u,&k);    
      for(int j=0;j<k;j++){
    scanf("%d %d",&V,&C);
    D[u][V] = C;
      }    
  }
  for(int i=0;i<n;i++)D[i][i] = 0;
  for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j]= min(D[i][j],D[i][k] + D[k][j]);
  for(int i=0;i<n;i++)printf("%d %d\n",i,D[0][i]);
  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;
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

#define MAX 100
#define INF (1<<29)
#define rep(i,n) for(int i = 0 ; i < n ; i++)

int main(){
  int n;
  int d[MAX][MAX];

  fill(d[0],d[MAX],INF);

  cin >> n;
  rep(i,n){
    int u,k;
    cin >> u >> k;
    rep(j,k){
      int v,c;
      cin >> v >> c;
      d[u][v] = c;
    }
  }

  d[0][0] = 0;
  rep(k,n){
    rep(i,n){
      rep(j,n){
	d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
      }
    }
  }

  rep(i,n){
    cout << i << " " << d[0][i] << endl;
  }

  return 0;
}

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

#define INF 20000000
typedef struct Edge edge;

struct Edge{
  int src,dst,weight;
  Edge(int start,int end,int cost) :
	src(start),dst(end),weight(cost) {}
};

bool operator < (const edge &e,const edge &f){
  return (e.weight != f.weight) ? (e.weight > f.weight) : (e.src != f.src) ? (e.src < f.src) : (e.dst < f.dst);
}

typedef vector<edge> Edges;

vector<int> dijkstra(Edges,int);

int main(int argc,char* argv[]){
  int n,v,k,dst,weight;
  Edges es;
  vector<int> vec;

  cin >> n;
  for(int i = 0;i < n;i++){
	cin>> v >> k;
	vec.push_back(v);
	for(int j = 0;j < k;j++){
	  cin >> dst >> weight;
	  edge e(i,dst,weight);
	  es.push_back(e);
	}
  }

  vector<int> dist = dijkstra(es,n);

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

vector<int> dijkstra(Edges es,int n){
  vector<int> dist(n);
  priority_queue<edge> que;
  Edges l[n];
  dist.assign(n,INF);
  dist[0] = 0;

  for(int i = 0;i < (int)es.size();i++){
	edge e = es[i];
	l[e.src].push_back(e);
  }

  for(int i = 0;i < (int)l[0].size();i++)
	que.push(l[0][i]);

  while(!que.empty()){
	edge e = que.top();
	que.pop();
	if(dist[e.dst] > dist[e.src] + e.weight){
	  dist[e.dst] = dist[e.src] + e.weight;

	  for(int i = 0;i < (int)l[e.dst].size();i++)
		que.push(l[e.dst][i]);
	}
  }

  return dist;
}

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 min;
   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 ) {
      min = INFTY; 
      int a = -1;
      for ( int i = 0; i < n; i++ ) {
         if ( min > d[i] && color[i] != BLACK ) {
             a = i;
             min = d[i];
         }
      }

      if ( a == -1 ) break;
      color[a] = BLACK;
      
      for ( int v = 0; v < n; v++ ) {
         if ( color[v] != BLACK && M[a][v] != INFTY ) {
            if ( d[v] > d[a] + M[a][v] ) {
               d[v] = d[a] + M[a][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 < n; j++ ) {
      cin >> v >> c;
      M[u][v] = c;
      }
   }

   dijkstra();

   return 0;
}