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 <bits/stdc++.h>
using namespace std;
int main(void){
    int n,i,j;
    cin>>n;
    vector<bool> used(n,false);
    vector<int> dist(n,99999999);
    map<int,vector<pair<int,int>>> v;
    for(i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        for(j=0;j<b;j++){
            int to,cost;
            cin>>to>>cost;
            v[i].emplace_back(to,cost);
        }
    }
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
    q.push(make_pair(0,0));
    dist[0]=0;
    while(!q.empty()){
        pair<int,int> e;
        e=q.top();q.pop();
        used[e.second]=true;
        dist[e.second]=min(dist[e.second],e.first);
        for(auto p:v[e.second]){
            if(!used[p.first]){
                q.push(make_pair(dist[e.second]+p.second,p.first));
            }
        }
    }
    for(i=0;i<n;i++){
        cout<<i<<' '<<dist[i]<<endl;
    }
}

C++: #include <bits/stdc++.h>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

map<ll, ll> d;
priority_queue< Pll, vector<Pll>, greater<Pll> > que;
map<ll, vector<Pll> > edges;

void dijkstra(ll start){
    d[start] = 0;
    que.push(Pll(0, start));

    while(!que.empty()){
        Pll v = que.top(); que.pop();
        if(d.find(v.second) != d.end() && d[v.second] < v.first) continue;
        for(Pll e: edges[v.second]){
            if(d.find(e.first) == d.end() || d[e.first] > d[v.second] + e.second){
                d[e.first] = d[v.second] + e.second;
                que.push(Pll(d[e.first], e.first));
            }
        }
    }
}

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n;
    ll u, k, c, v;
    cin >> n;
    rep(n){
        cin >> u >> k;
        repp(j, k){
            cin >> v >> c;
            edges[u].emplace_back(v, c);
        }
    }

    dijkstra(0);
    repp(u, n) cout << u << " " << d[u] << endl;

}

C++: #include <iostream>

using namespace std;
static const int mx=107;
static const int inf=(1<<21);

int n,m[mx][mx];

void dijkstra()
{
	int minv;
	int d[mx],color[mx];
	
	for (int i=0;i<n;i++) {
		d[i]=inf;
		color[i]=0;
	}
	
	d[0]=0;
	color[0]=1;
	while (1) {
		minv=inf;
		int u=-1;
		for (int i=0;i<n;i++) {
			if(minv>d[i]&&color[i]!=2)
			{
				u=i;
				minv=d[i];
			}
		}
		if(u==-1)break;
		color[u]=2;
		for (int v=0;v<n;v++) {
			if(color[v]!=2&&m[u][v]!=inf)
			{
				if(d[v]>d[u]+m[u][v])
				{
					d[v]=d[u]+m[u][v];
					color[v]=1;
				}
			}
		}
	}
		for (int i=0;i<n;i++) 
			cout<<i<<" "<<(d[i]==inf?-1:d[i])<<endl;
}
int main(int argc, char *argv[]) {
	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<bits/stdc++.h>
using namespace std;
#define int long long
int e[111][111],d[111],used[111];
signed main(){
  int n;
  cin>>n;
  int INF=1LL<<55LL;
  fill((int*)e,(int*)(e+111),INF);
  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;
      e[u][v]=min(e[u][v],c);
    }
  }
  memset(used,0,sizeof(used));
  for(int i=0;i<n;i++)d[i]=INF;
  d[0]=0;
  while(1){
    int u=-1;
    for(int i=0;i<n;i++){
      if(used[i])continue;
      if(d[i]==INF)continue;
      if(u<0||d[i]<d[u])u=i;
    }
    if(u<0)break;
    used[u]=1;
    for(int i=0;i<n;i++)d[i]=min(d[i],d[u]+e[u][i]);
  }
  for(int i=0;i<n;i++)cout<<i<<" "<<d[i]<<endl;
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

int n;
using P = pair<int, int>;
int l[100][100];
int d[100];

void dijkstra(int start) {
    fill(d, d + 100, inf);
    d[start] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    while(!que.empty()) {
        P p = que.top();
        que.pop();
        rep(i, n)
            if(chmin(d[i], p.first + l[p.second][i]))
                que.push({d[i], i});
    }
}

int main() {
    Fill(l, inf);
    cin >> n;
    rep(i, n) {
        int u, k;
        cin >> u >> k;
        rep(i, k) {
            int v, c;
            cin >> v >> c;
            l[u][v] = c;
        }
    }
    dijkstra(0);
    rep(i, n) cout << i << ' ' << d[i] << endl;
}

C++: #include <iostream>
#include <queue>
#include <vector>

using namespace std;

#define INF (10000001)

typedef pair<int, int> Edge;

int main()
{
    priority_queue<Edge,vector<Edge>,greater<Edge> > pq;
    vector<vector<Edge> > e;
    vector<int> d;
    Edge etemp;
    int n,u,k,v,c;
    cin >> n;
    e.resize(n);
    d.resize(n);
    for(int i=0; i<n; ++i) {
        cin >> u >> k;
        for(int j=0; j<k; ++j) {
            cin >> v >> c;
            e[u].push_back(Edge{c,v});
        }
        d[u]=INF;
    }

    d[0]=0;
    for(auto x : e[0]) {
        pq.push(x);
    }
    while(!pq.empty()) {
        etemp=pq.top(); pq.pop();
        v=etemp.second;
        c=etemp.first;
        if(d[v]<c) continue;
        d[v]=c;
        for(auto x : e[v]) {
            if(d[x.second]<=c+x.first) continue;
            pq.push(Edge{c+x.first,x.second});
        }
    }
    for(int i=0; i<n; ++i) {
        cout << i << " " << d[i] << endl;
    }
    return 0;
}