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++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b)  for(int i=a;i<=b;++i)
#define rep(i, n) for(int i=0;i<n;++i)
using namespace std;
struct TRAVEL{
  int to;
  int cost;
};
int main(){
  int n;  cin >> n;
  vector<TRAVEL> g[n];
  int d[n];
  bool flag=true;
  rep(i, n){
    int u, k; cin >> u >> k;
    d[i] = 1000000000;
    rep(j, k){
      int v, c; cin >> v >> c;
      g[i].push_back({v, c});
    }
  }
  d[0] = 0;
  while(flag){
    flag = false;
    rep(i, n){
      rep(j, g[i].size()){
        int check = d[g[i][j].to];
        d[g[i][j].to] = min(d[i]+g[i][j].cost, d[g[i][j].to]);
        if(check != d[g[i][j].to])  flag = true;
        cout << "debug : " << i << " " << g[i][j].to << " " << d[g[i][j].to] << endl;
       }
    }
  }
  rep(i, n) cout << i << " "<< d[i] << endl;
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

const int MAX = 100;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
int n, M[MAX][MAX];

int dijkstra()
{
	int minv;
	int d[MAX];
	int color[MAX];

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

	d[0] = 0;
	color[0] = GRAY;

	while (1) {
		minv = INF;
		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 (M[u][v] != INF && color[v] != BLACK) {
				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] == INF ? -1 : d[i]) << endl;
	}

	return 0;
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			M[i][j] = INF;

	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>

using namespace std;

static const int N = 100;
static const int I=(1<<21);
static const int W= 0;
static const int G =1;
static const int B =2;

int n,M[N][N];

int dij(){
  int minv,d[N],color[N];
  for(int i=0;i<n;i++){
    d[i]=I;
    color[i]=W;
  }

  d[0]=0;
  color[0]=G;

  while(1){
    minv=I;
    int u=-1;
    for(int i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=B){
        u=i;
        minv=d[i];
      }
    }
    if(u==-1)break;
    color[u]=B;
    for(int v=0;v<n;v++){
      if(color[v]!=B&&M[u][v]!=I){
        if(d[v]>d[u]+M[u][v]){
          d[v]=d[u]+M[u][v];
          color[v]=G;
        }
  
      
          
      }
      }
        
    }
  for(int i=0;i<n;i++){
    cout<<i<<" "<<(d[i]==I ? -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]=I;
    }
  }

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

  dij();
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#define INF 1<<10
using namespace std;
int n;
int A[1000][1000];
int d[1000];
bool used[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;
	D[V][u] = 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>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
const int maxn=10010;
const int Max=10000001;
int n;
int dis[maxn];
bool vis[maxn];

struct edge
{
	int u,v,w;
	edge(int u=0,int v=0,int w=Max):u(u),v(v),w(w){}
};
vector<edge> G[maxn];

struct node
{
	int d,id;
	bool operator < (const node& rhs) const
	{
		return d>rhs.d;
	}
	node(int d=0,int id=0):d(d),id(id){}
};
priority_queue<node> Q;

void dijkstra(int s)
{
	memset(dis,0x7f,sizeof(dis));
	memset(vis,0,sizeof(vis));
	dis[s]=0;
	Q.push(node(0,s));
	while(!Q.empty())
	{
		node u=Q.top();
		Q.pop();
		if(vis[u.id]) continue;
		vis[u.id]=1;
		for(unsigned int i=0;i<G[u.id].size();++i)
		{
			edge e=G[u.id][i];
			if(dis[e.v]>dis[u.id]+e.w)
			{
				dis[e.v]=dis[u.id]+e.w;
				Q.push(node(dis[e.v],e.v));
			}
		}
	}
}

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

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;++i)
	{
		int id,k;
		scanf("%d%d",&id,&k);
		for(int j=0;j<k;j++)
		{
			int v,w;
			scanf("%d%d",&v,&w);
			G[id].push_back(edge(id,v,w));
		}
	}
	dijkstra(0);
	print();
	return 0;
}