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 n;
typedef pair<int, int> P;
const int N = 110;
vector<P> G[N];
int dis[N];
bool vis[N];

void dijkstra() {
    memset(vis, false, sizeof(vis));
    for (int i = 0; i < n; i++) dis[i] = INT_MAX;
    priority_queue<P, vector<P>, greater<P>> heap;
    heap.push({0, 0});
    dis[0] = 0;

    while (!heap.empty()) {
        int u = heap.top().second, cost = heap.top().first;
        heap.pop();
        if (vis[u]) continue;
        vis[u] = true;
        for (int i = 0; i < G[u].size(); i++) {
            int v = G[u][i].second, len = G[u][i].first;
            if (!vis[v] && dis[u] + len < dis[v]) {
                dis[v] = dis[u] + len;
                heap.push({dis[v], v});
            }
        }
    }
}

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

    dijkstra();

    for (int u = 0; u < n; u++) {
        cout << u << " " << dis[u] << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
#define int long long
#define rng(i, l, r) for (size_t i = (l); i < (r); ++i)
#define rep(i, n) rng(i, 0, n)
#define gnr(i, l, r) for (size_t i = (r)-1; i >= (l); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(obj) (obj).begin(), (obj).end()    //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend() //...,3,2,1

using namespace std;

const int INF = 1e18;
struct edge
{
    int to, cost;
};
using Graph = vector<vector<edge>>;

static const int MAX = 10000;

static const int YET = 0;
static const int CHK = 1;
static const int END = 2;

int n;
Graph G;

void dijkstra()
{
    priority_queue<pair<int, int>> pq;
    int seen[MAX];
    int dist[MAX];

    memset(seen, YET, sizeof(seen));
    //memset(dist, INF, sizeof(dist));
    rep(i, MAX) dist[i] = INF;

    dist[0] = 0;
    seen[0] = CHK;
    pq.push(make_pair(0, 0));

    while (!pq.empty())
    {
        auto minDistV = pq.top();
        pq.pop();
        int u = minDistV.second;
        int uc = minDistV.first * (-1);
        seen[u] = END;

        if (dist[u] < uc)
            continue;

        for (auto ne : G[u])
        {
            int nv = ne.to;
            int nvc = ne.cost;

            if (seen[nv] == END)
                continue;
            if (dist[u] + nvc < dist[nv])
            {
                dist[nv] = dist[u] + nvc;
                pq.push(make_pair(dist[nv] * (-1), nv));
                seen[nv] = CHK;
            }
        }
    }

    for (int i = 0; i < n; i++)
    {
        cout << i << " " << ((dist[i] == INF) ? -1 : dist[i]) << endl;
    }
}

void solve()
{

    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("./sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    G.resize(n);
    for (int i = 0; i < n; i++)
    {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++)
        {
            int vertex, cost;
            cin >> vertex >> cost;
            G[u].push_back((edge){vertex, cost});
        }
    }

    dijkstra();

    return;
}

signed main()
{
    solve();
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<climits>
using namespace std;
 
#define N 10000
int n;
 
int g[N][N];
 
int weight[N];
bool us[N];
 
//prim
void prim(){
 
  int v;
  
  weight[0]=0;
   
  while(true){
    v=-1;
    
    for(int i=0;i<n;i++){
      if(us[i]!=true && (v==-1 ||weight[i]<weight[v]))v=i;
    }
 
    if(v==-1)break;
    us[v]=true;
  
 
    for(int i=0;i<n;i++){
      if(weight[i]>(g[v][i]+weight[v])){
 
        weight[i]=(g[v][i]+weight[v]);
        //      cout <<"fsafa"<<endl;
      }
    }
  }
  
}
 
 
int main(){
 
  int u,k1,c,v;
 
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      g[i][j]=9953535;
    }
  }
 
  //load n
  cin >>n;
 
  //load data
  for(int i=0;i<n;i++){
    weight[i]=INT_MAX;
    us[i]=false;
    scanf("%d %d",&u,&k1);
    for(int j=0;j<k1;j++){
      scanf("%d %d",&v,&c);
      g[u][v]=c;
      //    cout <<g[i][j]<<" ";
    }
    //    cout <<endl;
  }
 
 
 
 
  //print
  prim();
 
  for(int i=0;i<n;i++){
    cout <<i<<" "<<weight[i]<<endl;
  }
  return 0;
 
}

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

static const int MAX=100;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
static const int INF=(1<<21);

int n,M[MAX][MAX];

void dig(){
  int color[MAX],d[MAX];
  for(int i=0;i<n;i++){
    color[i]=WHITE;
    d[i]=INF;
  }


d[0]=0;
color[0]=GRAY;

int minc,u;
while(1){
  minc=INF;
  u=-1;
  for(int i=0;i<n;i++){
    if(color[i]!=BLACK&&minc>d[i]){
      minc=d[i];
      u=i;
    }
  }
if(u==-1) break;
  color[u]=BLACK;

  for(int v=0;v<n;v++){
    if(M[u][v]!=INF&&color[v]!=BLACK){
      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 u,k,v,c;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v>>c;
      M[u][v]=c;
    }
  }

  dig();
  return 0;
}

C++: #include<iostream>
using namespace std;
static const int INF=(1<<21);
int M[100][100];
void dij(int n, int d[], int color[]){
	d[0]=0;
	color[0]=1;
	int minv;
	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;
				}
			}
		}
	}
}
int main(){
	int n;
	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;
		}
	}
	int d[n], color[n];
	for(int i=0; i<n; i++){
		d[i]=INF;
		color[i]=0;
	}
	dij(n, d, color);
	for(int i=0; i<n; i++){
		cout<<i<<" ";
		if(d[i]==INF)
			cout<<-1<<endl;
		else
			cout<<d[i]<<endl;
	}
	return 0;
}