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 <bits/stdc++.h>
#define MAX_E 1000000
#define MAX_V 100000
#define INF 1e9
typedef long long ll;
using namespace std;
/*??????????????????????????? O(V*E)*/

//??????from????????????to???????????????cost??????
struct edge{int from, to, cost;};
edge es[MAX_E]; //???
ll d[MAX_V];   //???????????¢
int V,E;        //V???????????°???E????????°

//s???????????????????????????????????????????????¢????±???????.
void Bellman_Ford(int s){
  for(int i=0; i<V ;i++) d[i]=INF;
  d[s]=0;
  while(true){
    bool update=false;
    for(int i=0; i<E ;i++){
      edge e = es[i];
      if(d[e.from] != INF && d[e.to]> d[e.from] + e.cost){
	d[e.to] = d[e.from] + e.cost;
	update = true;
      }
    }
    if(!update) break;
  }
}

//true??????????????????????????¨??????
bool find_negative_loop(){
  memset(d,0,sizeof(d));

  for(int i=0; i<V ;i++){
    for(int j=0; j<E ;j++){
      edge e = es[j];
      if(d[e.to] > d[e.from] + e.cost){
	d[e.to] = d[e.from] + e.cost;
	
	//n??????????????´??°???????????????????????????????????¨?????????
	if(i == V-1) return true;
      }
    }
  }
  return false;
}

int main(){
  cin>>V;
  for(int i=0;i<V;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0,v,c;j<k;j++){
      cin>>v>>c;
      es[E++]=(edge){u,v,c};
    }
  }
  Bellman_Ford(0);
  for(int i=0;i<V;i++)
    cout<<i<<' '<<d[i]<<endl;
  /*  for(int i=0;i<V;i++){
    Bellman_Ford(i);
    cout <<i<<" "<<d[0]<<endl;
  }*/
}

C++: #include<stdio.h>
#include<string.h>
int n, dis[105], a[105][105];
bool vst[105];
void dijkstra()
{
    memset(vst, 0, sizeof(vst));
    memset(dis, 0x3f3f3f3f, sizeof(dis));
    dis[0] = 0;
    for(int i = 0; i < n; i++)
    {
        int k = n;
        for(int j = 0; j < n; j++)
            if(!vst[j] && dis[k] > dis[j]) k = j;
        vst[k] = 1;
        for(int j = 0; j < n; j++)
            if(!vst[j] && dis[j] > dis[k] + a[k][j])
                dis[j] = dis[k] + a[k][j];
    }
}
int main()
{
    scanf("%d", &n);
    memset(a, 0x3f3f3f3f, sizeof(a));
    for(int i = 1; i <= n; i++)
    {
        int m, j;
        scanf("%d%d", &m, &j);
        while(j--){
            int k, t;
            scanf("%d%d", &k, &t);
            if(t < a[m][k]) a[m][k] = t;
        }
    }
    dijkstra();
    for(int i = 0; i < n; i++)
        printf("%d %d\n", i, dis[i]);
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int u,k,v,c;
	int i,j;
	int MAX=INT_MAX;
	int box[101][101];
	cin>>n;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(i==j)	box[i][j]=0;
			else		box[i][j]=MAX;
		}
	}
	for(i=0;i<n;i++){
		cin>>u>>k;
		for(j=0;j<k;j++){
			cin>>v>>c;
			box[u][v]=c;
		}
	}
	// for(i=0;i<n;i++){
		// for(j=0;j<n;j++){
			// if(box[i][j]==MAX)	cout<<"★"<<" ";
			// else				cout<<box[i][j]<<" ";
		// }
		// cout<<endl;
	// }
	for(k=0;k<n;k++){
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(box[i][k]!=MAX&&box[k][j]!=MAX){
					box[i][j]=min(box[i][j],box[i][k]+box[k][j]);
				}
			}
		}
	}
	// for(i=0;i<n;i++){
		// for(j=0;j<n;j++){
			// if(box[i][j]==MAX)	cout<<"★"<<" ";
			// else				cout<<box[i][j]<<" ";
		// }
		// cout<<endl;
	// }
	for(i=0;i<n;i++){
		cout<<i<<" "<<box[0][i]<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define N_MAX 100

int M[N_MAX][N_MAX];
int d[N_MAX];
bool is_belong_to_sssp[N_MAX];

int main(){

  int n;
  scanf("%d", &n);

  //initialize
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      M[i][j] = INT_MAX;
    }
  }

  // read weigts
  for(int i=0; i<n; i++){
    int u, k;
    scanf("%d %d", &u, &k);
    for(int j=0; j<k; j++){
      int v,c;
      scanf("%d %d", &v, &c);
      M[u][v] = c;
    }
  }

  // initialize cost
  d[0] = 0;
  is_belong_to_sssp[0] = false;
  for(int i=1; i<n; i++){
    d[i] = INT_MAX;
    is_belong_to_sssp[i] = false;
  }

  //dijkstra's algorithm
  for(int i=0; i<n; i++){
    // select node u in V-S that has minimum cost
    int min_cost = INT_MAX;
    int u = 1;
    for(int j=0; j<n; j++){
      if(!is_belong_to_sssp[j] && d[j] < min_cost){
        u = j;
        min_cost = d[j];
      }
    }

    // add u to is_belong_to_sssp
    is_belong_to_sssp[u] = true;

    // update node in V-S and adjacent to u
    for(int v=0; v<n; v++){
      if(!is_belong_to_sssp[v] && M[u][v] != INT_MAX){
        if(d[u] + M[u][v] < d[v]){
          d[v] = d[u] + M[u][v];
        }
      }
    }
  }

  // output
  for(int i=0; i<n; i++){
    printf("%d %d\n", i, d[i]);
  }

  return 0;
}

C++: #include <queue>
#include <cstdio>
#include <vector>
using namespace std;
int V, E, s, t, p, q, d[100]; vector<int> G[100];
int main() {
	scanf("%d%d", &V, &E);
	for(int i = 0; i < V; i++) {
		scanf("%d%d", &s, &t);
		for(int j = 0; j < t; j++) {
			scanf("%d%d", &p, &q);
			G[i].push_back(make_pair(p, q));
		}
	}
	for(int i = 1; i < V; i++) d[i] = 999999999;
	priority_queue<pair<int, int> > que; que.push(make_pair(0, 0));
	while(!que.empty()) {
		int v = que.top().second; que.pop();
		for(int i = 0; i < G[v].size(); i++) {
			int u = G[v][i].first, w = G[v][i].second;
			if(d[u] > d[v] + w) {
				d[u] = d[v] + w;
				que.push(make_pair(-d[u], u));
			}
		}
	}
	for(int i = 0; i < V; i++) printf("%d %d\n", i, d[i]);
	return 0;
}