Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)

	g := makeGraph(n)
	for i := 0; i < n; i++ {
		u := getNextInt(scanner)
		k := getNextInt(scanner)
		for ii := 0; ii < k; ii++ {
			v := getNextInt(scanner)
			c := getNextInt(scanner)
			g[u][v] = c
		}
	}

	ans := make([]int, n)
	im := make(IntMap, 1)
	im.increment(0)
	for len(im) < n {
		min := 1 << 30
		x := -1
		for u := range im {
			for v := 0; v < n; v++ {
				if im.get(v) != 0 {
					continue
				}
				if min > ans[u]+g[u][v] {
					min = ans[u] + g[u][v]
					x = v
				}
			}
		}
		im.increment(x)
		ans[x] = min
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", i, ans[i]))
	}
	writer.Flush()
}

func makeGraph(n int) [][]int {
	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		for ii := 0; ii < n; ii++ {
			g[i][ii] = 1 << 30
		}
	}

	return g
}

// IntMap ...
type IntMap map[int]int

func (m IntMap) get(key int) int {
	if _, ok := m[key]; ok {
		return m[key]
	}
	return 0
}
func (m IntMap) increment(key int) {
	if _, ok := m[key]; ok == false {
		m[key] = 0
	}
	m[key]++
}

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