Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
type Node struct {
	cost int
	done bool
}

type Edge struct {
	to, cost int
}

const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	nodes := make([]Node, N)
	for i := 0; i < N; i++ {
		nodes[i].cost = INF
	}
	E := make([][]Edge, N)
	for i := 0; i < N; i++ {
		id, k := sc.nextInt(), sc.nextInt()
		for j := 0; j < k; j++ {
			to, cost := sc.nextInt(), sc.nextInt()
			E[id] = append(E[id], Edge{to, cost})
		}
	}
	nodes[0].cost = 0
	for {
		cur := 0
		minCost := INF
		for i := 0; i < N; i++ {
			n := nodes[i]
			if !n.done && n.cost < minCost {
				cur = i
				minCost = n.cost
			}
		}
		if minCost == INF {
			break
		}
		nodes[cur].done = true
		for i := 0; i < len(E[cur]); i++ {
			to, cost := E[cur][i].to, E[cur][i].cost+nodes[cur].cost
			if !nodes[to].done && cost < nodes[to].cost {
				nodes[to].cost = cost
			}
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprintln(wtr, i, nodes[i].cost)
	}
	wtr.Flush()
}

C++: #include <bits/stdc++.h> 
using namespace std; 
typedef long long ll; 
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I) 
const ll INF=1e9+7; 
const ll N = 101; 


class dijkstra{ 
//0indexed 
public: 
	int v,startv; 
	vector<int> d; 
	vector<vector<pair<int,int> > >e; 

void initsize(int n0){ 
	d.resize(n0); 
	for(int i=0;i<n0;i++)d[i]=INT_MAX; 
	vector<pair<int,int> > ep; 
	for(int i=0;i<n0;i++)e.push_back(ep); 
	v=n0; 
} 

void initstart(int s){ 
	startv=s;
	d[s]=0;
}

void make_edge(int x,int y,int cost){ 
	e[x].push_back(make_pair(y,cost)); 
	e[y].push_back(make_pair(x,cost)); 
}

void make_edgedir(int x,int y,int cost){ 
	e[x].push_back(make_pair(y,cost)); 
}

void calcdistance(){ 
	// <-cost,x> 
	//cost startv->x 
	priority_queue<pair<int,int> > q; 
	pair<int,int> p; 
	vector<bool> did; 
	for(int i=0;i<v;i++)did.push_back(false); 
	did[startv]=true; 
	for(int i=0;i<e[startv].size();i++){ 
		p.first=-e[startv][i].second; 
		p.second=e[startv][i].first; 
		q.push(p); 
	}

	while(q.size()!=0){ 
		pair<int,int> p; 
		p=q.top(); 
		q.pop(); 
		int x,costsx; 
		x=p.second; 
		costsx=-p.first; 
		if(did[x]==true)continue; 
		did[x]=true; 
		d[x]=costsx; 

		for(int i=0;i<e[x].size();i++){ 
			p.first=-(d[x]+e[x][i].second); 
			p.second=e[x][i].first; 
			if(did[p.second]==false)q.push(p); 
		} 
	} 
} 

}; 



int main(){ 
	dijkstra di;
	int n;
	cin>>n;
	di.initsize(n);
	di.initstart(0);
	FOR(i,0,n){
		int u,k;
		cin>>u>>k;
		FOR(j,0,k){
			int x,co;
			cin>>x>>co;
			di.make_edgedir(u,x,co);
		}
	}
	di.calcdistance();
	FOR(i,0,n){
		cout<<i<<" "<<di.d[i]<<endl;
	}
	return 0; 
}

C++: #include <stdio.h>
#define INF (1<<21)

int main(void)
{
 int i,j,n,m,u,k,l,v,c,a[10000],b[10000],d[10000][10000];

 scanf("%d",&n);
 
 for(i=0;i<n;i++){
 	scanf("%d %d",&u,&k);
 	a[i]=INF;
 	b[i]=0;
 	for(j=0;j<k;j++){
 		scanf("%d %d",&v,&c);
 		d[u][v]=c;
 	}
 }
 a[0]=0;
 
 while(1){
 	
 	l=-1;
 	m=INF;
 	
 	for(i=0;i<n;i++){
 		if(a[i]<m && b[i]==0){
 			m=a[i];
 			l=i;
 		}
 	}
 	
 	if(l==-1) break;
 	
 	b[l]=1;
 	
 	for(i=0;i<n;i++){
 		if(a[i]>=d[l][i]+a[l]) a[i]=d[l][i]+a[l];
 	}
 }
 
 for(i=0;i<n;i++){
 	if(a[i]==INF) printf("%d -1\n",i);
 	else printf("%d %d\n",i,a[i]);
 }
 
 return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define INF 1<<29
#define MAXV 100

int V;      //????????°
int cost[MAXV+10][MAXV+10];

vector<int> dijkstra(int s){
    vector<int> d(V,INF);
    bool used[MAXV+10];
    for(int i=0;i<MAXV+10;i++) used[i]=false;

    d[s]=0;
    while(true){
        //??????????????????????????????????????§s??????????????¢???????°?????????????v??¨??????
        int v=-1;
        for(int u=0;u<V;u++){
            if(!used[u] and (v==-1 or 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]);
        }
    }
    return d;
}

int main(){
    // initialize
    for(int i=0;i<MAXV+10;i++) for(int j=0;j<MAXV+10;j++) cost[i][j]=INF;

    cin >> V;
    for(int i=0;i<V;i++){
        int u,k;cin>>u>>k;
        for(int j=0;j<k;j++){
            int v,c;cin>>v>>c;
            cost[i][v]=c;
//            cost[v][i]=c;
        }
    }

    vector<int> dis = dijkstra(0);
    for(int i=0;i<dis.size();i++){
        printf("%d %d\n",i,dis[i]);
    }
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>

#define MAX 100
static const int INFTY =(1<<21);

int n,M[MAX][MAX];
int unvisited=0,decide=1,comp_decide=2;

void dijkstra(){
	int d[MAX];
	int state[MAX];
	for(int i=0;i<n;i++){
		d[i]=INFTY;
		state[i]=unvisited;
	}
	d[0]=0;
	state[0]=0;
	while(1){
		int mincost=INFTY,u=-1;
		for(int i=0;i<n;i++){
			if(d[i]<mincost&&state[i]!=comp_decide){
				u=i;
				mincost=d[i];
			}
		}
		if(u==-1) break;
		state[u]=comp_decide;
		for(int v=0;v<n;v++){
			if(state[v]!=comp_decide&&M[u][v]!=INFTY){
				if(d[v]>d[u]+M[u][v]){
					d[v]=d[u]+M[u][v];
					state[v]=decide;
				}
			}
		}
	}
	for(int i=0;i<n;i++){
			printf("%d %d\n",i,(d[i]==INFTY ? -1:d[i]));
	}
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			M[i][j]=INFTY;
		}
	}
	int u,k,v,c;
	for(int i=0;i<n;i++){
		scanf("%d %d",&u,&k);
		for(int j=0;j<k;j++){
			scanf("%d %d",&v,&c);
			M[u][v]=c;
		}
	}
	dijkstra();
}

C++: #include<iostream>
#define INF 1<<30
using namespace std;
int main() {
  int n; cin >> n;
  int graph[100][100];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) graph[i][j] = INF;
  for (int i = 0; i < n; ++i) {
    int u, k, v; cin >> u >> k;
    for (int j = 0; j < k; ++j) {
      cin >> v;
      cin >> graph[u][v];
    }
  }
  int mincost[100], flag[100] = {};
  mincost[0] = 0;
  for (int i = 1; i < n; ++i) mincost[i] = INF;
  while (1) {
    int x = -1;
    for (int i = 0; i < n; ++i)
      if (!flag[i] && (x == -1 || mincost[x] > mincost[i])) x = i;
    if (x == -1) break;
    flag[x] = 1;
    for (int i = 0; i < n; ++i)
      if (mincost[i] > mincost[x]+graph[x][i]) mincost[i] = mincost[x]+graph[x][i];
  }
  for (int i = 0; i < n; ++i) cout << i << " " << mincost[i] << endl;
  return 0;
}