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<vector>
#include<algorithm>
#define MAX_V 100
#define INF 1e9
using namespace std;
int cost[MAX_V][MAX_V];
int d[MAX_V];
bool used[MAX_V];
int V;
void dijkstra(int s)
{
	for (int i = 0; i < MAX_V; i++)

	{
		d[i] = INF;
		used[i] = false;
	}
	d[s] = 0;

	while (true)
	{
		int v = -1;
		for (int u = 0; u < V; u++)
		{
			if (!used[u] && (v == -1 || d[u] < d[v]))
			{
				v = u;
			}
		}
		if (v == -1)
		{
			break;
		}
		used[v] = true;

		for (int u = 0; u < V; u++)
		{
			d[u] = min(d[u], d[v] + cost[v][u]);
		}


	}
}
int main()
{

	for (int i = 0; i < MAX_V; i++)
	{
		for (int j = 0; j < MAX_V; j++)
		{
			cost[i][j] = INF;
		}
	}
	cin >> V;
	for (int i = 0; i < V; i++)
	{
		int u;
		cin >> u;
		int k;
		cin >>  k;
		for (int j = 0; j < k; j++)

		{
			int v;
			cin >> v;
			int c;
			cin >> c;
			cost[u][v] = c;

		}
	}

	dijkstra(0);

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

}

C++: #include <iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;
int inf=(1<<20);


int main(void){
    int n,u,q,c;
int m[100][100];
int d[100];
int w[100];

    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            m[i][j]=inf;
        }
        d[i]=inf;
        cin>>q>>c;
        for(int j=0;j<c;j++){
            int k,l;
            cin>>k>>l;
            m[q][k]=l;
        }
    }
    
    d[0]=0;
    while(1){
        u=-1;
        int min=inf+1;
        for(int i=0;i<n;i++){
            if(min>d[i]&&d[i]!=-1){
                min=d[i];
                u=i;
            }
        }
        if(u==-1)break;
        w[u]=d[u];
        for(int i=0;i<n;i++){
            if(d[i]!=-1&&d[i]>m[u][i]+d[u]){
                d[i]=m[u][i]+d[u];
            }
        }

        d[u]=-1;
    }
  for(int i=0;i<n;i++){
      cout<<i<<" "<<w[i]<<endl;
  }
    return 0;
}

C++: #include <bits/stdc++.h>
const int INF = 500000;
using namespace std;

int main(void){
  bool used[100];
  int n, G[100][100];
  cin >> n;
  for(int i=0; i < 100; i++){
    used[i] = false;
    for(int j=0; j < 100; j++){
      G[i][j] = INF;
    }
  }
  for(int i=0; i < n; i++){
    int vtmp, k;cin >> vtmp >> k;
    for(int j=0; j < k; j++){
      int v, c; cin >> v >> c;
      G[vtmp][v] = c;   
    }
  }

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

  for(int i=0; i < n; i++){
    int mind = INF;
    int minind = -1;
    for(int j=0; j < n; j++){
      if(used[j] == false && d[j] < mind){
        mind = d[j]; minind = j;
      }
    }
    if(minind == -1) break;
    used[minind] = true;
    for(int j=0; j < n; j++){
      if(used[j] == false && G[minind][j] != INF){
        if(d[minind] + G[minind][j] < d[j]){
          d[j] = d[minind] + G[minind][j];
        }
      }
    }
  }
  for(int i=0; i < n; i++){
    cout << i << " " << d[i] << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;
#include <functional>

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 100;

int N;

class Edge{
public:
	int from, to, cost;
	Edge(int from = 0, int to = 0, int cost = 0) :
		from(from), to(to), cost(cost){}

	bool operator < (const Edge &e) const{
		return cost < e.cost;
	}
	bool operator >(const Edge &e) const{
		return cost > e.cost;
	}

};

static const int INFTY = (1 << 21);

class Node{
public:
	vector<Edge> edges;
	int dist;
	Node(){
		dist = INFTY;
	}
};

class Graph{
public:
	vector<Node> nodes;
	Graph(int n) {
		rep(i, n) { Node n;  nodes.push_back(n); }
	}
};

class Data{

public:
	int dist; Edge edge;
	Data(int dist, Edge edge) {
		this->dist = dist;
		this->edge = edge;
	}

	bool operator < (const Data &d) const{
		return dist < d.dist;
	}
	bool operator >(const Data &d) const{
		return dist > d.dist;
	}

};

int main() {

	cin >> N;
	Graph g(N);

	rep(i, N){
		int no; cin >> no;
		int n_edge; cin >> n_edge;

		rep(j, n_edge){
			int from = no;
			int to; cin >> to;
			int cost; cin >> cost;
			Edge e(from, to, cost);
			g.nodes[no].edges.push_back(e);
		}
	}

	int i = 0;
	g.nodes[i].dist = 0;

	priority_queue<Data, vector<Data>, greater<Data> > pq;
	for (auto e : g.nodes[i].edges){
		int dist = g.nodes[i].dist + e.cost;
		Data d(dist, e);
		pq.push(d);
	}

	int ret = 0;
	while (!pq.empty()){
		Data d = pq.top(); pq.pop();
		Node *n = &g.nodes[d.edge.to];
		if (n->dist != INFTY){ continue; }
		n->dist = d.dist;

		for (auto e : n->edges){
			int dist = n->dist + e.cost;
			Data d(dist, e);
			pq.push(d);
		}
	}

	rep(i, N){
		cout << i << " " << g.nodes[i].dist << endl;
	}
}

C++: #include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
 
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];

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

  REP(i, n) {
    d[i] = INFTY;
    color[i] = white;
  }

  d[0] = 0;
  color[0] = gray;

  while( 1 ) {
    minv = INFTY;
    u = -1;
    REP(i, n) {
      if (minv > d[i] && color[i] != black ) {
        u = i;
        minv = d[i];
      }
    }
    if (u == -1) break;
    color[u] = black;
    REP(v, n) {
      if (color[v] != black && M[u][v] != INFTY) {
        if (d[v] > d[u] + M[u][v]) {
          d[v] = d[u] + M[u][v];
          p[v] = u;
          color[v] = gray;
        }
      }
    }
  }
  REP(i, n) {
    cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
  }
}

int main() {
  cin >> n;
  REP(i, n) {
    REP(j, n) {
      M[i][j] = INFTY;
    }
  }

  int k, c, u, v;
  REP(i, n) {
    cin >> u >> k;
    REP(j, k) {
      cin >> v >> c;
      M[u][v] = c;
    }
  }
  dijkstra();
  return 0;
}