Go: package main

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

const (
	white int = iota
	gray
	black
)

type node struct {
	id     int
	parent int
	edge   []int
	weight []int
	color  int
}

type graph struct {
	nodes    []node
	distance []int
}

var infty = 1 << 32
var null = -1

func constructgraph() *graph {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)

	g := &graph{make([]node, n), make([]int, n)}

	for i := 0; i < n; i++ {
		id := nextInt(sc)
		edges := nextInt(sc)
		n := node{}
		n.id = id
		n.edge = make([]int, edges)
		n.weight = make([]int, edges)
		n.color = white
		for j := 0; j < edges; j++ {
			to := nextInt(sc)
			w := nextInt(sc)
			n.edge[j] = to
			n.weight[j] = w
		}
		g.nodes[id] = n
	}
	return g
}

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

func (g *graph) preparedijkstra(s int) {
	for i := 0; i < len(g.nodes); i++ {
		g.nodes[i].color = white
		g.nodes[i].parent = null
		g.distance[i] = infty
	}
	g.distance[s] = 0
}

func (g *graph) dijkstra(s int) []int {
	g.preparedijkstra(s)

	for {
		var u int
		mincost := infty
		for i, d := range g.distance {
			if g.nodes[i].color != black && mincost > d {
				mincost = d
				u = i
			}
		}

		if mincost == infty {
			break
		}

		g.nodes[u].color = black

		for i, e := range g.nodes[u].edge {
			if g.nodes[e].color != black {
				if g.distance[e] > g.distance[u]+g.nodes[u].weight[i] {
					g.distance[e] = g.distance[u] + g.nodes[u].weight[i]
					g.nodes[e].parent = u
					g.nodes[e].color = gray
				}
			}
		}
	}
	return g.distance
}

func printShortestPath(d []int) {
	for i, v := range d {
		fmt.Printf("%d %d\n", i, v)
	}
}

func main() {
	g := constructgraph()
	d := g.dijkstra(0)
	printShortestPath(d)
}

C++: #define dbg(...) fprintf(stderr,__VA_ARGS__)
#define dpr(x) cerr<<#x<<": "<<x<<endl;
#define dprc(c) do{cerr<<#c<<":";for(auto&_i:(c)){cerr<<" "<<_i;}cerr<<endl;}while(0)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int INF = 1e9+7;
#define all(c) (c).begin(), (c).end()
#define tr(i,c) for(auto i=(c).begin();i!=(c).end();i++)
#define rtr(i,c) for(auto i=(c).rbegin();i!=(c).rend();i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

int main(int argc, char **argv)
{
  int n;
  scanf("%d", &n);

  vector<vector<pii>> G(n, vector<pii>());
  for (int i = 0; i < n; i++) {
    int u, k, v, c;
    scanf("%d %d", &u, &k);
    for (int j = 0; j < k; j++) {
      scanf("%d %d", &v, &c);
      G[u].pb(pii(v, c));
    }
  }

  vi d(n, INF);
  vector<bool> visited(n, false);
  int vc = 0;
  priority_queue<pii, vector<pii>, greater<pii>> q;

  d[0] = 0;
  visited[0] = true;
  vc = 1;
  q.push(pii(0, 0));
  
  while(!q.empty()) {
    pii p = q.top(); q.pop();
    int u = p.second;

    if (d[u] < p.first) continue;

    visited[u] = true;
    for (auto e:G[u]) {
      int v = e.first;
      int c = e.second;
      if (!visited[v] && (d[u] + c < d[v])) {
        d[v] = d[u] + c;
        q.push(pii(d[v], v));
      }
    }
  }

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

  return 0;
}

C++: #include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

const int MAX = 100;


enum col
  {
   WHITE = 0,
   GRAY =  1,
   BLACK = 2,
  };

using namespace std;
const int INF = 0x7fffffff;

int M[MAX][MAX];
col color[MAX];
int d[MAX];
int p[MAX];
int n;

void daikusutora(int s){
  int ii,vv;

  //初期化
  for(ii=0;ii<n;ii++){
    color[ii] = WHITE;
    d[ii] = INF;
    p[ii] = -1;
  }
  
  d[s] = 0;
  p[s] = -1;
  
  int mincost,u;
  while(1){
    mincost = INF;
    u = -1;

    //次に選ぶ頂点の決定
    for(ii=0;ii<n;ii++){
      if(color[ii] != BLACK && d[ii] < mincost){

        mincost = d[ii];
        u = ii;
        //cout << "u:" << u << endl;
      }
    }

    //ループの終了条件
    if(mincost == INF){
      break;
    }

    color[u] = BLACK;
    //cout << "color:" << u << endl;

    //次のパスの選択候補
    for(vv=0;vv<n;vv++){
      //未探索の頂点かつ u -> vv へのパスがある場合
      if(color[vv] != BLACK && M[u][vv] != INF){
        //次に探索する候補
        if(d[u] + M[u][vv] < d[vv]){
          //cout << "vv:" << vv << endl;
          d[vv] = d[u] + M[u][vv];
          //color[vv] = GRAY;
        }
      }
    }
    
  }
  
}

int main(){

  long ii,jj,kk;
  int u,k,v,c;
  vector<int> a;

  cin >> n;

  //初期化
  for(ii=0;ii<n;ii++){
    for(jj=0;jj<n;jj++){
      M[ii][jj] = INF;
    }
  }
  
  for(ii=0;ii<n;ii++){

    cin >> u >> k;
    //cout << "u:" << u << "k:" << k << endl;
    for(jj=0;jj<k;jj++){
      cin >> v >> c;
      M[ii][v] = c;
    }
    
  }

  //for(ii=0;ii<n;ii++){
  //  for(jj=0;jj<n;jj++){
  //    cout << M[ii][jj] << " " ;
  //  }
  //  cout << endl;
  //}

  daikusutora(0);

  for(ii=0;ii<n;ii++){
    cout << ii << " " << d[ii] << endl;
  }
  return 0;
}

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