Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

const T = 10000000

var n int
var A [101][101]int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func Shortestsearch() {
	var Minimum int
	var d, color [100]int
	var u int

	for i := 0; i < n; i++ {
		d[i] = T
		color[i] = 0
	}

	d[0] = 0
	color[0] = 1

	for {
		Minimum = T
		u = -1
		for i := 0; i < n; i++ {
			if Minimum > d[i] && color[i] != 2 {
				u = i
				Minimum = d[i]
			}
		}
		if u == -1 {
			break
		}
		color[u] = 2
		for j := 0; j < n; j++ {
			if color[j] != 2 && A[u][j] != T {
				if d[j] > d[u]+A[u][j] {
					d[j] = d[u] + A[u][j]
					color[j] = 1
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d\n", i, d[i])
	}
}
func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			A[i][j] = T
		}
	}
	for i := 0; i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			v := nextInt()
			c := nextInt()
			A[u][v] = c
		}
	}
	Shortestsearch()
}

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