Go: package main

import (
	"fmt"
	"container/heap"
)

type Node struct {
	Id int
	Dis int
}

type PriorityQueue []*Node

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dis < pq[j].Dis
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(*Node))
}

func (pq *PriorityQueue) Pop() interface{} {
	n := len(*pq)
	pop := (*pq)[n-1]
	*pq = (*pq)[0:n-1]
	return pop
}

func main() {
	var n int
	fmt.Scan(&n)

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
			fmt.Scan(&c[u][j])
		}

		if u == 0 {
			d[u] = 0
		} else {
			d[u] = 1 << 30
		}
		pq.Push(&Node{u, d[u]})
	}
	heap.Init(&pq)

	for pq.Len() > 0 {
		node := heap.Pop(&pq).(*Node)
		for i := 0; i < len(g[node.Id]); i++ {
			nextId := g[node.Id][i]
			nextDis := node.Dis + c[node.Id][i]
			if nextDis < d[nextId] {
				d[nextId] = nextDis
				heap.Push(&pq, &Node{nextId, nextDis})
			}
		}
	}

	for i := 0; i < n; i++ {
		fmt.Println(i, d[i])
	}
}

C++: #include<cstdio>
#include<iostream>
#define INF 200001 
using namespace std;
int main(){
 int u,k,C,V,A[1000][1000],D[1000][1000],n;
  scanf("%d",&n);
   for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j] = INF;
  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;
      }    
  }
  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 <vector>
#include <queue>
using namespace std;


int main() {
    int N; cin >> N;
    int u, k, v, c; 
    const int inf = 100000000;
    

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

    int dist[N]; 
    priority_queue<pair<int, int> > que;

    for (int i = 0; i < N; ++i) {
        if (i) dist[i] = inf;
        else dist[i] = 0;
    }
    que.push(make_pair(0, 0));

    while (!que.empty()) {
        pair<int, int> f = que.top(); que.pop();
        int cur_cost = f.first*(-1);
        int cur_vtx = f.second;

        if (dist[cur_vtx] < cur_cost) continue;

        for (int i = 0; i < G[cur_vtx].size(); ++i) {
            int next_cost = G[cur_vtx][i].first;
            int next_vtx = G[cur_vtx][i].second;

            if (dist[next_vtx] > cur_cost + next_cost) {
                dist[next_vtx] = cur_cost + next_cost;
                que.push(make_pair(dist[next_vtx]*(-1), next_vtx));
            }
        }   
    }

    for (int v = 0; v < N; ++v) cout << v<< " " << dist[v] << endl;

    return 0;
}

C++: #include <iostream>

using namespace std;

static const int MAX = 100;
static const int INF = 1 << 30;
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] = INF;
        color[i] = WHITE;
    }

    d[0] = 0;

    while (true){
        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( color[v] != BLACK && M[u][v] !=INF){
                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;
    }
}

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>
#include <queue>
#include <utility>
#include <vector>
#include <functional>
using namespace std;
int cost[100][100];
const int INF = 10000000;
int dijkstra(int n,int s,int g){
	typedef pair<int,int> P;
	priority_queue<P,vector<P>,greater<P> > pq;
	P p,tp;
	for(int i = 0;i < n;++i){
		p.first = cost[s][i];
		p.second = i;
		if(i == s) p.first = 0;
		pq.push(p);
	}
	while(!pq.empty()){
		p = pq.top();
		pq.pop();
		if(p.second == g) break;
		for(int i = 0;i < n;++i){
			if(cost[p.second][i] != INF && p.first != INF){
				tp.first = p.first + cost[p.second][i];
				tp.second = i;
				pq.push(tp);
			}
		}
	}
	return p.first;
}
int main(){
	int n,m,a,b,c;
	cin >> n;
	for(int i = 0;i < 100;++i){
		for(int j = 0;j < 100;++j){
			cost[i][j] = INF;
		}
	}
	for(int i = 0;i < n;++i){
		cin >> a >> m;
		for(int j = 0;j < m;++j){
			cin >> b >> c;
			cost[a][b] = c;
		}
	}
	for(int i = 0;i < n;++i){
		cout << i << " " << dijkstra(n,0,i) << endl;
	}
	return 0;
}

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;
}