Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const (
	INFTY = 1 << 21
	NIL   = -1
)

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph [][]int

func (g *Graph) dikstra(n int) string {
	var (
		u, minv = 0, 0
	)

	d := make([]int, n)
	color := make([]int, n)

	for i := 0; i < n; i++ {
		d[i] = INFTY
		color[i] = WHITE
	}
	d[0] = 0
	color[0] = GRAY

	for {
		minv = INFTY
		u = -1
		for 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 v := 0; v < n; v++ {
			if color[v] != BLACK && (*g)[u][v] != INFTY {
				if d[v] > d[u]+(*g)[u][v] {
					d[v] = d[u] + (*g)[u][v]
					color[v] = GRAY
				}
			}
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d ", i))
		if d[i] == INFTY {
			out.WriteString(fmt.Sprintf("%d\n", -1))
			continue
		}
		out.WriteString(fmt.Sprintf("%d\n", d[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	g := make(Graph, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		for j := 0; j < n; j++ {
			g[i][j] = INFTY
		}
	}

	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())

		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			sc.Scan()
			c, _ := strconv.Atoi(sc.Text())

			g[u][v] = c
		}
	}

	return g.dikstra(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: #include <iostream>
#include <vector>
#define rep(i,N) for(int i = 0; i<(int)(N); i++)
#define REP(i,k,N) for(int i = k; i<(int)(N); i++)
#define INF 100000000
typedef long long ll;
using namespace std;

int main(){
        int n;
        cin >> n;
        vector< vector<int> > G(n, vector<int>(n,INF));
        int u,k,v,c;
        rep(i,n){
                cin >> u >>k;
                rep(j,k){
                        cin >> v >> c;
                        G[u][v] = c;
                }
        }

        vector<ll> d(n, INF * n);
        d[0]=0;
        bool update = true;
        while(update) {
                update  = false;
                rep(from,n) {
                        if(d[from] >= INF * n) continue;

                        rep(to,n){
                                if(from == to) continue;

                                if(d[to] > d[from] + G[from][to]) {
                                        update = true;
                                        d[to] = d[from] + G[from][to];
                                }

                        }
                }
        }
        rep(i,n){
                cout << i << " " << d[i] << endl;
        }

        return 0;
}

C++: //B//
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
 
int main()
{
	int n;
	scanf("%d",&n);
	int data[105][105]={0};
	int vis[105][105]={0};
	int dis[105]={0};
	int tag[105]={0};
	int i,j,k;
	for(i=0;i<n;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		for(j=0;j<y;j++)
		{
			int a,b;
			scanf("%d %d",&a,&b);
			data[x][a]=b;
			vis[x][a]=1;
		}
	}
	int mina=-1; 
	tag[0]=1;
	for(i=1;i<n;i++)
	{
		if(vis[0][i]==1&&tag[i]==0)
		{
			dis[i]=data[0][i];
			if(mina==-1) mina=data[0][i];				
			else if(data[0][mina]>data[0][i]) mina=i;
		}	
	}
	for(j=1;j<n;j++)
	{
		for(i=1;i<n;i++)
		{
			if(vis[mina][i]==1&&tag[i]==0)
			{
				if(dis[i]==0)
				{
					dis[i]=dis[mina]+data[mina][i];
				}
				else
				{
					dis[i]=min(dis[i],dis[mina]+data[mina][i]);
				}
				
			}	
		}
		mina=-1;
		for(i=1;i<n;i++)
		{
			if(tag[i]==0)
			{
				if(mina==-1) mina=i;				
				else if(dis[mina]>dis[i]) mina=i;
			}	
		}
		tag[mina]=1;
	}	
	
	printf("0 0\n");
	for(k=1;k<n;k++)
	{
		printf("%d %d\n",k,dis[k]);
	}
	
	 
	return 0;
}

C++: #include <iostream>
#include <cstring> 
#include <algorithm> 
#include <vector> 
#define INF 2000000000 //??¨?????????????????¢????¶??????????????????????????????§????????°???????????¨????????????????????????
             
#define MAX_V 100
     using namespace std;
     int v,u,c,k,vertex;//number of vertices
     int d[MAX_V];
     int ver[100]={};
     int path[100][100]={};
     int path_exist[100][100];
     int min_index;
     bool used[MAX_V];
     int num_used=0,l;
     vector<int> q;
     void dijkstra(int s)
     {
             fill(d,d+v,INF);
             memset(used,false,sizeof(used));//(s,val,end)?????¢?????§s??????end?????§?????¢???????¢???????false??§?????????
             d[s]=0;
             while(q.size()-num_used != 0){
             		while(used[l]==true){
             			l++;
             		}
             		min_index=l;
                     for(int j=0;j<q.size();j++){
                     	if(!used[j]){//???????????¢????????????????¨??????????????????????????????¶
                     		if(d[min_index] > d[j]/*??´??????*/)
                     		min_index=q.at(j);
                     	}
                     }
                        used[min_index]=true;
                        num_used+=1;
                        for(int j=0;j<ver[min_index];j++){//min_index????????°????????????????????????edge????????¨??????????????????????????°
			  d[path_exist[min_index][j]]=min(d[path_exist[min_index][j]], d[min_index] + path[min_index][path_exist[min_index][j]]);/*??´??????*/
                        } 
            }
            return;
    }
    int main(){
        cin>>v;

        for(int i=0; i<v;i++){
        	cin>>u;
        	cin>>k;
        	ver[u]=k;
        	q.push_back(i);
        	for(int j=0;j< k ; j++){
        		cin>>vertex;
        		cin>>c;
        		path[u][vertex]= c;
        		path_exist[u][j]=vertex;

        	}
        }

        dijkstra(0);
        for(int i=0;i<v;i++){
        	cout<<i<<" "<<d[i]<<endl;
        }
        return 0;
    }