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