Go: package main

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

const (
	MAX_N      = 100
	MAX_WEIGHT = 100000
)

type Edge struct {
	start  int
	end    int
	weight int
}

type ShortestInfo struct {
	edges    []Edge
	shortest int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	shortestList := make([]ShortestInfo, n)
	for i := 1; i < n; i++ {
		shortestList[i] = ShortestInfo{edges: []Edge{}, shortest: MAX_N*MAX_WEIGHT + 1}
	}

	adjacentMatrix, err := createAdjacentMatrix(n, sc)
	if err != nil {
		panic(err)
	}

	sssp([]int{1}, shortestList, adjacentMatrix)
	for _, v := range shortestList {
		fmt.Printf("%d %d\n", v.getEnd()-1, v.shortest)
	}
}

func (si ShortestInfo) getEnd() int {
	if len(si.edges) == 0 {
		return 1
	} else {
		return si.edges[len(si.edges)-1].end
	}
}

func createAdjacentMatrix(n int, sc *bufio.Scanner) ([][]int, error) {
	adjacentMatrix := make([][]int, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		adjacentMatrix[id] = make([]int, n)
		for j := 0; j < n; j++ {
			adjacentMatrix[id][j] = -1
		}
		vertexNum, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		for j := 0; j < vertexNum; j++ {
			v, err := nextInt(sc)
			if err != nil {
				return nil, err
			}
			c, err := nextInt(sc)
			if err != nil {
				return nil, err
			}
			adjacentMatrix[id][v] = c
		}
	}
	return adjacentMatrix, nil
}

func sssp(nodeStack []int, shortestList []ShortestInfo, adjacentMatrix [][]int) {
	for len(nodeStack) > 0 {
		currentNode := nodeStack[0]
		nodeStack = nodeStack[1:]
		currentShortest := getShortest(currentNode, shortestList)
		adjacents := findAdjacents(currentNode, adjacentMatrix)
		for i := 0; i < len(adjacents); i++ {
			adj := adjacents[i]
			if currentShortest.shortest+adj.weight < getShortest(adj.end, shortestList).shortest {
				setShortest(adj.end, adj, currentShortest, shortestList)
				nodeStack = append(nodeStack, adj.end)
			}
		}
	}
}

func getShortest(node int, shortestList []ShortestInfo) ShortestInfo {
	return shortestList[node-1]
}

func setShortest(node int, edge Edge, currentShortest ShortestInfo, shortestList []ShortestInfo) {
	newEdges := make([]Edge, len(currentShortest.edges)+1)
	for i := 0; i < len(newEdges)-1; i++ {
		newEdges[i] = currentShortest.edges[i]
	}
	newEdges[len(newEdges)-1] = edge
	shortestInfo := ShortestInfo{edges: newEdges, shortest: currentShortest.shortest + edge.weight}
	shortestList[node-1] = shortestInfo
}

func findAdjacents(currentNode int, adjacentMatrix [][]int) []Edge {
	adjacents := adjacentMatrix[currentNode-1]
	edges := []Edge{}
	for i, v := range adjacents {
		if v > 0 {
			edges = append(edges, Edge{start: currentNode, end: i + 1, weight: v})
		}
	}
	return edges
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <utility>
using namespace std;
//_____
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define err(...) fprintf(stderr, __VA_ARGS__)
#define show(x) cerr << #x << ':' << x << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
const int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};
#define INF 0x3f3f3f3f
#define LEN 1000011
#define NIL -1
//_______

int N;
vector <pii> G[101];
int mcos[101];

void dijkstra(int s)
{
   priority_queue < pii, vector<pii>, greater<pii> > pq;
   pq.push( mkp(0, s) );
   memset( mcos, INF, sizeof(mcos) );
   mcos[s] = 0;

   while( !pq.empty() ){
      const pii tmp = pq.top(); pq.pop();
      if( mcos[tmp.se] < tmp.fi )continue;

      for( const auto& v : G[tmp.se] ){
         const int nc = v.fi + tmp.fi;
         if( chmin( mcos[v.se], nc )) pq.push( mkp(nc, v.se) );
      }
   }
   return ;
}

signed main()
{
   FAST();
   cin >> N;
   rep(i, N){
      int u, k, to, c;
      cin >> u >> k;
      while(k--){
         cin >> to >> c;
         G[i].pb( mkp(c,to) );
      }
   }
   dijkstra(0);
   rep(i, N){
      cout << i << ' ' << mcos[i] << '\n';
   }
}

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

void dijkstra(int s);
const int Infty = 20000000;

int **M,*d,*p,n;
string *color;

int main(){
	cin>>n;
	M = new int*[n]; for(int i=0;i<n;i++) M[i] = new int[n];
	d = new int[n]; p = new int[n]; color = new string[n];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++) M[i][j] = -1;
	}

	for(int i=0;i<n;i++){
		int vertex,deg,e,w;
		cin>>vertex>>deg;
		for(int j=0;j<deg;j++){
			cin>>e>>w;
			M[i][e]  = w;
		}
	}

	dijkstra(0);

	for(int i=0;i<n;i++) delete [] M[i]; delete [] M;
	delete [] d; delete [] p; delete [] color;
}

void dijkstra(int s){
	for(int i=0;i<n;i++){
		d[i] = Infty; color[i] = "WHITE";
	}
	d[s] = 0; p[s] = -1;

	while(true){
		int u , mindist = Infty;
		for(int i=0;i<n;i++){
			if(color[i]!="BLACK" && d[i]<mindist){
				mindist = d[i];
				u = i;
			}
		}

		if(mindist==Infty) break;

		color[u] = "BLACK";

		for(int v=0;v<n;v++){
			if(color[v]!="BLACK" && M[u][v]!=-1){
				if(d[u]+M[u][v]<d[v]){
					d[v] = d[u]+M[u][v];
					p[v] = u;
					color[v] = "GRAY";
				}
			}
		}
	}

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

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
constexpr auto INF = 2147483647;
typedef long long ll;

static const int MAX = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, Adj_Marix[MAX][MAX];

void dijkstra(){
  int minv;
  int distance[MAX], color[MAX];
  //init
  for(int i=0;i<n; i++){
    distance[i] = INF;
    color[i] = WHITE;
  }
  distance[0] = 0;
  color[0] = GRAY;
  while(1){
    minv = INF;
    int u  = -1;
    // Find next point
    for(int i =0; i<n; i++){
      if( minv > distance[i] && color[i] != BLACK){
        u = i;
        minv = distance[i];
      }
    }
    //if cant find next point
    if(u == -1) break;
    // Refresh dictance for adj points
    color[u] = BLACK;
    for(int v=0; v<n; v++){
      if(color[v] != BLACK && Adj_Marix[u][v] != INF){
        if(distance[v] > distance[u] + Adj_Marix[u][v]){
          distance[v] = distance[u] + Adj_Marix[u][v];
          color[v] = GRAY;
        }
      }
    }
  }
  for(int i =0; i<n; i++){
    cout << i << " " << (distance[i] == INF ? -1: distance[i] ) << endl;
  }
}

int main(){

  cin >> n;
  rep(i,n){
    rep(j,n){
      Adj_Marix[i][j] = INF;
    }
  }

  int k, c, u, v;
  rep(i,n){
    cin >> u >> k;
    rep(j,k){
      cin >> v >> c;
      Adj_Marix[u][v] = c;
    }
  }

  dijkstra();

  return 0;
}