Go: package main

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

const NIL = -1

type Node struct {
	id     int
	weight int
}

func init() {
	sc.Split(bufio.ScanWords)
}

type NodeHeap []Node

func (h NodeHeap) Len() int           { return len(h) }
func (h NodeHeap) Less(i, j int) bool { return h[i].weight < h[j].weight }
func (h NodeHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *NodeHeap) Push(x interface{}) {
	*h = append(*h, x.(Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()

	list := make([][]int, n)
	weight := make([]int, n)
	for i := range list {
		list[i] = make([]int, n)
		weight[i] = NIL
		for j := range list[i] {
			list[i][j] = NIL
		}
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		for j := 0; j < k; j++ {
			v := scanInt()
			w := scanInt()
			list[u][v] = w
		}
	}

	start := Node{id: 0, weight: 0}
	h := &NodeHeap{start}
	heap.Init(h)

	for h.Len() > 0 {
		node := heap.Pop(h).(Node)
		if weight[node.id] != NIL {
			continue
		}
		weight[node.id] = node.weight

		for i, w := range list[node.id] {
			if w == NIL {
				continue
			}
			heap.Push(h, Node{id: i, weight: w + node.weight})
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		fmt.Fprint(w, i)
		fmt.Fprint(w, " ")
		fmt.Fprint(w, weight[i])
		fmt.Fprintln(w)
	}
	w.Flush()
}

C++: #include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
using namespace std;

struct uft{
    vector<ll> par;
    uft(ll n) {
        par.resize(n);
        rep(i,n)par[i]=i;
    }

    ll find(ll a){
        if(par[a]==a){
            return a;
        }else {
            return find(par[a]);
        }
    }

    void unite(ll a,ll b){
        par[find(a)]=find(b);
    }

    bool same(ll a,ll b){
        return find(a) == find(b);
    }
};

struct edge{
    ll s,t,w;
};

bool sortw(edge a,edge b) {
    return a.w < b.w;
}

int main() {
    const ll inf = 1e12;
    ll n;
    cin>>n;
    vector<vector<ll>> matrix(n,vector<ll>(n));
    rep(i,n){
        rep(j,n){
            if(i==j){
                matrix[i][j]=0;
            }else{
                matrix[i][j]=inf;
            }
        }
    }
    rep(i,n) {
        ll u,k;
        cin>>u>>k;
        rep(j,k){
            ll c,w;
            cin>>c>>w;
            matrix[u][c]=w;
        }
    }
    rep(k,n){
        rep(i,n){
            rep(j,n){
                if(matrix[i][k]<inf && matrix[k][j]<inf && matrix[i][j]>matrix[i][k]+matrix[k][j]){
                    matrix[i][j]=matrix[i][k]+matrix[k][j];
                }
            }
        }
    }
    rep(i,n){
        cout<<i<<" "<<matrix[0][i]<<endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define int(x) int x; scanf("%d",&x)
#define input(x) scanf("%d",&x)
#define rep(x,n) for(int x = 0; x < n; x++)
#define _br printf("\n")
#define INF 2000000000

vector<pair<int,int> > PathList[100];
int d[100];
bool complete[100];

void dijkstra(int n,vector<pair<int,int> > PathList[]){
    rep(i,n){
        d[i] = INF;
        complete[i] = false;
    }
    d[0] = 0;
    
    int count = 0;
    
    while (count != n) {
        int mind = INF;
        int mindi = 0;
        rep(i,n){
            if (!complete[i] && d[i] < mind) {
                mind = d[i];
                mindi = i;
            }
        }
        
        complete[mindi] = true;
        count++;
        
        rep(i,PathList[mindi].size()){
            if (PathList[mindi][i].second + d[mindi] < d[PathList[mindi][i].first]) {
                d[PathList[mindi][i].first] = PathList[mindi][i].second + d[mindi];
            }
        }
    }
}


int main(){
    int(n);
    rep(i,n){
        int(k);int(num);
        rep(j,num){
            int(s);int(t);
            PathList[i].push_back(make_pair(s,t));
        }
    }
    
    dijkstra(n,PathList);
    
    rep(i,n){
        printf("%d %d\n",i,d[i]);
    }
    
    return 0;
}

C++: #include<stdio.h>
#include<algorithm>
#define  INF  100000  
using namespace std;
typedef long long ll;
ll q[210][210];
int  p[210];
ll  dis[210];

void Dijkstra(int N){
	fill(dis,dis+210,INF);
	dis[0]=0;
	while(p[N-1]==0){
		int x=-1;
		ll mini=INF;
		for(int i=0;i<N;i++){
			if(p[i]==1) continue;
			if(mini>dis[i]){
				mini=dis[i];
				x=i;
			}
		}
		p[x]=1;
		for(int y=0;y<N;y++){
			if(p[y]==1)  continue;
			dis[y]=min(dis[y],dis[x]+q[x][y]);
		}
	}
}
 
int main()
{
    int u,N,k,v;
	ll C;
	while(~scanf("%d",&N))
	{
		fill(q[0],q[0]+210*210,INF);
		fill(p,p+210,0);
		int M=N;
		while(N--)
		{
		    scanf("%d%d%",&u,&k);
		    for(int i=0;i<k;i++){
		    	scanf("%d%lld",&v,&C);
		    	q[u][v]=min(q[u][v],C);
			    q[v][u]=q[u][v];
			}
		}
		Dijkstra(M);
		for(int i=0;i<M;i++){
			printf("%d %lld\n",i,dis[i]);
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct edge{
    long long from,to,cost;
    edge(){}
    edge(long long f,long long t,long long c) : from(f),to(t),cost(c){}
};

vector<long long> bellmanford(int s,const vector<edge>& es,int V){
    constexpr long long inf = 1ll << 60;
    vector<long long> d(V,inf);
    d[s] = 0;
    for(int i=0;i<V;i++){
        for(const edge& e : es){
            if(d[e.from]!=inf && d[e.to]>d[e.from]+e.cost){
                d[e.to] = d[e.from] + e.cost;
            }
        }
    }
    return d;
}

signed main(){
    int n;cin>>n;
    vector<edge> es;
    for(int i=0;i<n;i++){
        int u,k;
        cin >> u >> k;
        for(int j=0;j<k;j++){
            int c,v;
            cin >> v >> c;
            es.emplace_back(edge(u,v,c));
        }
    }
    auto d = bellmanford(0,es,n);
    for(int i=0;i<n;i++){
        cout << i <<  " " << d[i] << endl;
    }
}

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