Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

//make priority queue
type Item struct {
	id       int
	priority int // this state is priority and distans from start
	index    int
}

type PriorityQueue []*Item

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

// we want the ascending-priority-queue.
// So we use less than here.
func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}

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

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1 //for safety
	*pq = old[0 : n-1]
	return item
}

func (pq *PriorityQueue) update(dist int, id int) {
	for _, i := range *pq {
		if i.id == id {
			if i.priority > dist {
				i.priority = dist
			}
		}
	}
}

// the main code
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func dikstra(dist [][]int, n int) []int {
	// preparate priority queue
	inf := 1 << 30
	pq := make(PriorityQueue, n)
	shortests := make([]int, n)
	for i := 0; i < n; i++ {
		pq[i] = &Item{
			id:       i,
			priority: inf,
			index:    i,
		}

		shortests[i] = inf
	}
	pq[0].priority = 0
	shortests[0] = 0
	heap.Init(&pq)

	for pq.Len() > 0 {
		item := heap.Pop(&pq).(*Item)
		shortests[item.id] = item.priority
		for id, d := range dist[item.id] {
			if d != -1 {
				pq.update(item.priority+d, id)
			}
		}
		heap.Init(&pq)
	}
	return shortests
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	// init
	n := nextInt(sc)
	dist := make([][]int, n)
	for i := 0; i < n; i++ {
		dist[i] = make([]int, n)
		for j := 0; j < n; j++ {
			dist[i][j] = -1
		}
	}

	// std Input
	for i := 0; i < n; i++ {
		u := nextInt(sc)
		k := nextInt(sc)
		for j := 0; j < k; j++ {
			v, c := nextInt(sc), nextInt(sc)
			dist[u][v] = c
		}
	}

	shortests := dikstra(dist, n)
	for i, d := range shortests {
		fmt.Printf("%d %d\n", i, d)
	}
}

C++: 
#include <iostream>
using namespace std;
#define INFTY  (1 << 30)
const int Total = 101;
const int White = 0;//未访问
const int Grey = 1;//访问中
const int Black = 2;//不再访问
int  totalnode,Matrix[Total][Total], Color[Total], DistanceBetweenRootAndNode[Total],Parent[Total];
void includeBuildSingleSourceShortestPath()
{
	int minimumdistance, min;
	DistanceBetweenRootAndNode[0] = 0;//默认以0为根
	Parent[0] = -1;
	Color[0] = Grey;
	while (1)
	{
		minimumdistance = INFTY;
		for (int i = 0; i < totalnode; i++)
		{
			if (Color[i] != Black && DistanceBetweenRootAndNode[i] < minimumdistance)//在未访问或访问的点中找出最短的那个
				minimumdistance = DistanceBetweenRootAndNode[i], min = i;
		}
		if (minimumdistance == INFTY)break;//全部为黑色
		Color[min] = Black;//以min为基础搜相连的结点
		for (int i = 0; i < totalnode; i++)
		{
			if (Matrix[min][i] != 0 && Color[i] != Black)//找出相连且未被设为不再访问的结点
			{
				if (DistanceBetweenRootAndNode[min] + Matrix[min][i] < DistanceBetweenRootAndNode[i])
					//若根到点min的距离 加上 点min到点i的距离 小于 之前根到点i的距离
				{
					DistanceBetweenRootAndNode[i] = DistanceBetweenRootAndNode[min] + Matrix[min][i];
					Parent[i] = min;
					Color[i] = Grey;
				}

			}

		}


	}
}
int main()
{
	int frontnode,backnode,degree,distancebetweenfrontnodeandbacknode;
	cin >> totalnode;
	for (int i = 0; i < totalnode; i++)DistanceBetweenRootAndNode[i] = INFTY;//初始化距离
	for (int i = 0; i < totalnode; i++)Color[i] = White;
	for (int i = 0; i < totalnode; i++)
		for (int j = 0; j < totalnode; j++)
			Matrix[i][j] = 0;
	for (int i = 0; i < totalnode; i++)//有向图
	{
		cin >>frontnode>>degree;//frontnode中题目其实就默认从0开始
		for (int j = 0; j < degree; j++)
		{
			cin >> backnode>> distancebetweenfrontnodeandbacknode;
			Matrix[frontnode][backnode] = distancebetweenfrontnodeandbacknode;
		}
	}
	includeBuildSingleSourceShortestPath();
	for (int i = 0; i < totalnode; i++)
		cout << i <<" "<< DistanceBetweenRootAndNode[i]<<endl;
}

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