Go: package main

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

const BIG_COST = 200000

const (
	ST_NOT_YET = iota
	ST_JOINED
)

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

	nNodes := scanInt(sc)

	costs := make([][]int, nNodes)
	graph := make([][]int, nNodes)

	states := make([]int, nNodes)
	costSums := make([]int, nNodes)

	for i := 0; i < nNodes; i++ {
		costs[i] = make([]int, nNodes)
		costSums[i] = BIG_COST
	}

	for i := 0; i < nNodes; i++ {
		u := scanInt(sc)
		k := scanInt(sc)
		graph[u] = make([]int, k)
		for d := 0; d < k; d++ {
			v := scanInt(sc)
			graph[u][d] = v
			costs[u][v] = scanInt(sc)
		}
	}

	costSums[0] = 0
	for {
		minCost := BIG_COST
		var u int

		for i, cost := range costSums {
			if states[i] != ST_JOINED && cost < minCost {
				minCost = cost
				u = i
			}
		}

		if minCost == BIG_COST {
			break
		}

		states[u] = ST_JOINED

		for _, v := range graph[u] {
			cost := minCost + costs[u][v]
			if cost < costSums[v] {
				costSums[v] = cost
			}
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i, cost := range costSums {
		fmt.Fprintf(w, "%d %d\n", i, cost)
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

C++: #include <iostream>
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int MAX = 2000;

int d[110], p[110];
int color[110];

int main() {
  int n;
  std::cin >> n;
  int G[110][110];

  for(int i=0; i<n; ++i) {
    for(int j=0; j<n; ++j) {
      int v;
      std::cin >> v;
      if(v != -1) {
        G[i][j] = v;
      } else {
        G[i][j] = MAX;
      }
    }
  }

  for(int i=0; i<n; ++i) {
    color[i] = WHITE;
    d[i] = MAX;
  }

  d[0] = 0;
  p[0] = 0;

  while(true) {
    int mini_cost = MAX;
    int u;
    // 最小の重みとなる辺を探している
    for(int i=0; i<n; ++i) {
      if(color[i] != BLACK && d[i] < mini_cost) {
        mini_cost = d[i];
        u = i;
      }
    }

    if(mini_cost == MAX) {
      break;
    }

    color[u] = BLACK;

    for(int v=0; v < n; ++v) {
      if(color[v] != BLACK && G[u][v] != MAX) {
        if(G[u][v] < d[v]) {
          d[v] = G[u][v];
          p[v] = u;
          color[v] = GRAY;
        }
      }
    }
  }

  int d_sum = 0;
  for(int i=0; i<n; ++i) {
    d_sum += d[i];
  } 

  std::cout << d_sum << std::endl;
}

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