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 <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;

#define M 10005
#define INF 0x3f3f3f3f

int d[M][M],a[M],n;
bool vis[M];

void dijkstra()
{
    printf("%d!\n",n);
    for(int i=0;i<n;i++){
        if(i == 0) a[i]=0;
        else a[i]=INF;
    }
    memset(vis,0,sizeof(vis));
    for(int i=0;i<n;i++){
        int mark=-1,minn=INF;
        for(int j=0;j<n;j++){
            if(!vis[j]&&a[j]<minn){
                minn=a[j];
                mark=j;
            }
        }
        vis[mark]=1;
        for(int j=0;j<n;j++){
            if(!vis[j]){
                a[j]=min(a[j],a[mark]+d[mark][j]);
            }
        }
    }
    for(int i=0;i<n;i++){
        printf("%d %d\n",i,a[i]);
    }
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(j == i)
                d[i][j]=0;
            else
                d[i][j]=INF;
        }
    }
    for(int j=0;j<n;j++){
        int u,k;
        scanf("%d%d",&u,&k);
        for(int i=0;i<k;i++){
            int v,w;
            scanf("%d%d",&v,&w);
            d[u][v]=w;
        }
    }
    dijkstra();
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

#define MAX_V 100

struct edge {
	edge(int a, int b) {
		cost = a;
		to = b;
	}
	int cost;
	int to;
};

int n;
vector<vector<edge>> G;
vector<int> d;

void dijkstra(int s) {
	priority_queue<pii, vector<pii>, greater<pii>> que;
	d[s] = 0;
	que.push(pii(0, s));

	while (!que.empty()) {
		pii p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(pii(d[e.to], e.to));
			}
		}
	}

}

int main() {
	int n,u,k,tmpp,tmpw;
	cin >> n;
	d = vector<int>(n, INF);
	G = vector<vector<edge>>(n);
	rep (i,n) {
		cin >> u >> k;
		rep(j, k) {
			cin >> tmpp>>tmpw;
			G[u].emplace_back(tmpw, tmpp);
		}
	}
	dijkstra(0);
	rep(i, n) {
		cout << i << " " << d[i] << endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <bitset>

using namespace std;

int main()
{
	int N;
	cin>>N;
	
	vector<vector<int> > cost(N,vector<int>(N,10000001));
	cost[0][0]=0;
	pair<int,int> ddata;
	for(int i=0;i<N;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			cin>>ddata.first>>ddata.second;
			cost[u][ddata.first]=ddata.second;
		}
	}
	//
	
	vector<int> maxcost(N,10000001);
	
	priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > que;
	
	que.push(pair<int,int>(0,0));
	
	while(!que.empty()){
		int n=que.top().second;
		if(que.top().first<maxcost[n]){
			maxcost[n]=que.top().first;
		}
		for(int j=1;j<N;j++){
			if(que.top().first+cost[n][j]<maxcost[j]){
				maxcost[j]=que.top().first+cost[n][j];
				ddata.first=que.top().first+cost[n][j];
				ddata.second=j;
				que.push(ddata);
			}
		}
		que.pop();
	}
	
	for(int i=0;i<N;i++){
		cout<<i<<' '<<maxcost[i]<<endl;
	}
	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 min;
   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 ) {
      min = INFTY; 
      int a = -1;
      for ( int i = 0; i < n; i++ ) {
         if ( min > d[i] && color[i] != BLACK ) {
             a = i;
             min = d[i];
         }
      }
  
      if ( a == -1 ) break;
      color[a] = BLACK;
        
      for ( int v = 0; v < n; v++ ) {
         if ( color[v] != BLACK && M[a][v] != INFTY ) {
            if ( d[v] > d[a] + M[a][v] ) {
               d[v] = d[a] + M[a][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, a, v;
    
   for ( int i = 0; i < n; i++ ) {
      cin >> a >> k;  
  
      for ( int j = 0; j < k; j++ ) {
         cin >> v >> c;
         M[a][v] = c;
      }
   }
  
   dijkstra();
  
   return 0;
}