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++: #include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
typedef pair<int, int> P;
#define MAX_N (105)
#define MAX_C (100010)
#define INF (MAX_N * MAX_C)
vector<P> G[MAX_N];
int dist[MAX_N];
bool arrived[MAX_N];

int main()
{
    int n;
    scanf("%d", &n);
    
    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);
	    G[u].push_back( make_pair(v, c) );
	}
    }
    
    for ( int i = 0; i < n; i++ ) {
	dist[i] = INF;
    }

    dist[0] = 0;

    while ( true ) {
	int min_dist = INF;
	int u = -1;
	for ( int i = 0; i < n; i++ ) {
	    if ( !arrived[i] ) {
		if ( min_dist > dist[i] ) {
		    min_dist = dist[i];
		    u = i;
		}
	    }
	}
	
	if ( min_dist == INF ) break;
	arrived[u] = true;

	for ( int i = 0; i < G[u].size(); i++ ) {
	    P p = G[u][i];
	    int v = p.first;
	    int c = p.second;

	    if ( !arrived[v] ) {
		dist[v] = min( dist[v], dist[u] + c );
	    }
	}
    }

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

    return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream> 
using namespace std;  
const int maxn=105;
const int INF = 0x3f3f3f3f;   
int Map[maxn][maxn]; 
int n;
int min(int x,int y)
{
	if(x<y) return x;
	else  return y;
 } 
void floyd()  
{  
    for(int k=0;k<n;k++)  
        for(int i=0;i<n;i++)  
            for(int j=0;j<n;j++)  
            Map[i][j]=min(Map[i][j],Map[i][k]+Map[k][j]);  
}  
int main()  
{   
    scanf("%d",&n);
	     for(int i = 0 ; i<n ; i++)
			for(int j = 0 ; j<n ; j++) 
				Map[i][j] = i==j?0:INF;
    for(int i=0;i<n;i++) 
    {   int a,m;
	    scanf("%d%d",&a,&m);
        for(int i=0;i<m;i++)  
        {  
            int b,w;  
            scanf("%d%d",&b,&w);  
            Map[a][b]=Map[b][a]=min(Map[a][b],w);  
        }
    }
        floyd();
        for(int i=0;i<n;i++)
        {
        printf("%d %d\n",i,Map[0][i]); 
		}  
    return 0;  
}

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

const int INF = INT_MAX;
typedef pair<int, int> P;

struct edge {int to, cost;};

/*
[input]
const vector<vector<edge>> &graph : ??\?????°??????
int s : ?§????
int g : ??????
n*/
int dijkstra(const vector<vector<edge>> &graph, int s, int g ) {
  // ????????????????±?????????????????????????
  vector<int> d(graph.size(), INF);
  // ????§?????????????????????????0????????????
  d[s] = 0;
  // ??????????????????now
  set<P> now;
  // ????§?????????????now????????\
  now.insert(P(0, s));
  
  // now????????????????????§
  while(!now.empty()) {
    // ?????¨?????????????????????pos???????´?
    int pos = now.begin()->second;
    // ?????¨??????????????????????????????????±???????????????????????????????
    if (pos == g) {
      for(int i = 0; i <= g; i++) {
        cout << i << " " << d[i] << endl;
      }
      return INF;
    }
    // now????????¢?´¢?????????????¶????
    now.erase(now.begin());
    // ?????¨??????????????¨???????????¢?´¢
    for(auto ed: graph[pos]) {
      // ??\?¶??????????????????????????????????????????¨??????????????§????????????
      // ??¨??\?¶?????????§?????¨????????????????????????????????§???????????°
      if(d[ed.to] > d[pos] + ed.cost) {
        // now????????\?¶?????????????????±????????????????????????????
        now.erase(P(d[ed.to], ed.to));
        d[ed.to] = d[pos] + ed.cost;
        now.insert(P(d[ed.to], ed.to));
      }
    }
  }
  return INF;
}
  
int main() {
  int num;
  cin >> num;
  vector<vector<edge>> graph(num, vector<edge>());
  int f, n, k, v, c;
  for(int i = 0; i < num; i++) {
    cin >> f >> k;
    for(int j = 0; j < k; j++) {
      cin >> v >> c;
      graph[f].push_back(edge{v, c});
      graph[v].push_back(edge{f, c});
    }
  }
  dijkstra(graph, 0, num - 1);
  return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;

#define MAX_VERTEX 100
#define INF 1000000

int d[MAX_VERTEX][MAX_VERTEX];

int main() {
  int vertex_num;
  cin >> vertex_num;

  for(int i = 0; i < vertex_num; i++) {
    for(int j = 0; j < vertex_num; j++) {
      if (i == j) d[i][i] = 0;
      else d[i][j] = INF;
    }
  }

  for (int i = 0; i < vertex_num; i++) {
    int vertex, out;
    cin >> vertex >> out;
    for(int j = 0; j < out; j++) {
      int to, c;
      cin >> to >> c;
      d[vertex][to] = c;
    }
  }

  for (int k = 0; k < vertex_num; k++) {
    for (int i = 0; i < vertex_num; i++) {
      for (int j = 0; j < vertex_num; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

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

  return 0;
}

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

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
//int INF = (1<<21);

void dijkstra(void);

int n;
int M[MAX][MAX];

int main(){
  int i,j;
  int c,k,u,v;
  cin >> n;
  for( i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      M[i][j] = INFINITY;
      //M[i][j] = INF;
    }
  }
  for(i = 0; i < n; i++){
    cin >> u;
    cin >> k;
    for(j = 0; j < k; j++){
      cin >> v;
      cin >> c;
      M[u][v] = c;
    }
  }
  dijkstra();
  return 0;
}

void dijkstra(){
  int minV;
  int d[MAX],color[MAX];
  int u,v;
  int i;
  for(i = 0; i < n; i++){
    d[i] = INFINITY;
    //d[i] = INF;
    color[i] = WHITE;
  }
  d[0] = 0;
  color[0] = GRAY;
  while(1){
    minV = INFINITY;
    //minV = INF;
    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 && M[u][v] != INFINITY){
      //if(color[v] != BLACK && M[u][v] != INF){
        if(d[v] > d[u] + M[u][v]){
          d[v] = d[u] + M[u][v];
          color[v] = GRAY;
        }
      }
    }
  }
  for(i = 0; i < n; i++){
    cout << i << " " << (d[i] == INFINITY ? -1 : d[i]) << endl;
    //cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
  }
}