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>
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;
    
    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<stdio.h>
#define N 101
 
int main()
{
  int i,j,n,count=0,v,c,c1,v1;
  int G[N][N],col[N],d[N],pi[N],mincost,i2;
 
  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++)
      G[i][j] = -1;
  }
 
  scanf("%d",&n);
 
  for(i = 0; i < n; i++){
    scanf("%d%d",&v,&c);
    for(j = 0; j < c; j++){
      scanf("%d%d",&v1,&c1);
      G[v][v1] = c1;
    }
  }
 
  for(i = 0; i < n; i++){
    col[i] = 0;
    pi[i] = -1;
    d[i] = 10000001;
  }
 
  d[0] = 0;
 
  while(1){
    mincost = 10000001;
    for(i = 0; i < n; i++){
      if(col[i] != 2 && d[i] < mincost){
        mincost = d[i];
        i2 = i;
      }
    }
    if(mincost == 10000001)break;
 
    col[i2] = 2;
 
 
    for(i = 0; i < n; i++){
      if(G[i2][i] != -1 && col[i] != 2 && (G[i2][i]+d[i2]) < d[i]){
        pi[i] = i2;
        d[i] = G[i2][i] + d[i2];
        col[i] = 1;
      }
    }
  }
  for(i = 0; i < n; i++)printf("%d %d\n",i,d[i]);
    return 0;
}

C++: #include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long signed int ll;

constexpr ll NIL = -20000000000;

class path{
public:
    int from;
    int to;
    int dist;
    path(){
        from = -1;
        to = -1;
        dist = -1;
    }
    path(int from_,int to_,int dist_){
        from = from_;
        to = to_;
        dist = dist_;
    }
    static bool compare(const path& a,const path& b) {
        return a.from < b.from;
    }
    bool operator<(const path& e) const {
        return this->dist < e.dist;
    }
};

int n,u,k,v,c;
vector<path> w;
ll d[10000];

int main() {
    for(int i = 0;i < 10000;i++)d[i] = -NIL;
    cin >> n;
    for(int i = 0;i < n;i++) {
        cin >> u >> k;
        for(int j = 0;j < k;j++) {
            cin >> v >> c;
            w.push_back(path(u,v,c));
        }
    }
    sort(w.begin(),w.end(),path::compare);
    priority_queue<pair<int,int>> q;
    q.push(make_pair(0,0));
    d[0] = 0;
    while(!q.empty()) {
        auto y = q.top();q.pop();
        if(d[y.second] != y.first) continue;
        auto r = lower_bound(w.begin(),w.end(),path(y.second,0,0),path::compare);
        auto l = lower_bound(w.begin(),w.end(),path(y.second+1,0,0),path::compare);
        for(auto itr = r;itr < l;itr++) {
            if(d[itr->to] > d[itr->from] + itr->dist) {
                d[itr->to] = d[itr->from] + itr->dist;
                q.push(make_pair(d[itr->to],itr->to));
            }
        }
    }
    for(int i = 0;i < n;i++){
        cout << i << " " << d[i] << endl;
    }
}

C++: #include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

void dijkstra(vector<vector<pair<int, int>>>& edges, vector<int>& ds, int start) {
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    q.push(make_pair(0, start));
    while (!q.empty()) {
        int d = q.top().first;
        int u = q.top().second;
        q.pop();
        if (ds[u] >= 0) {
            continue;
        }
        ds[u] = d;
        for (auto p : edges[u]) {
            q.push(make_pair(d + p.second, p.first));
        }
    }
}

int main() {
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> edges(n);
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v, c;
            cin >> v >> c;
            edges[u].push_back(make_pair(v, c));
        }
    }

    vector<int> ds(n, -1);
    dijkstra(edges, ds, 0);

    for (int i = 0; i < n; i++) {
        cout << i << " " << ds[i] << endl;
    }
}