Go: package main

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

const (
	MAX_N      = 10000
	MAX_WEIGHT = 100000
)

type Edge struct {
	start  int
	end    int
	weight int
}

type ShortestInfo struct {
	edges    []Edge
	shortest int
}

func main() {
	doMain(os.Stdin)
}

func doMain(reader io.Reader) {
	sc := bufio.NewScanner(reader)
	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{0}, shortestList, adjacentMatrix)
	for _, v := range shortestList {
		fmt.Println(v.getEnd(), v.shortest)
	}
}

func (si ShortestInfo) getEnd() int {
	if len(si.edges) == 0 {
		return 0
	} 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]
}

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] = shortestInfo
}

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

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

C++: #include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
static const int N = 10000;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int,int>> adj[N];

void dijkstra(int s){
	priority_queue<pair<int,int>> PQ;
	int color[N];
	int d[N];
	for(int i=0;i<n;i++){
		color[i] = WHITE;
		d[i] = INFTY;
	}
	d[s] = 0;
	PQ.push(make_pair(s,0));
	color[s] = GRAY;

	while(!PQ.empty()){
		pair<int,int> f = PQ.top();PQ.pop();
		int u = f.second;
		color[u] = BLACK;
		if(d[u] < f.first*-1)continue;

		for(int j=0;j<adj[u].size();j++){
			int v=adj[u][j].first;
			if(color[v] == BLACK)continue;
			if(d[v]>d[u]+adj[u][j].second){
				d[v] = d[u] + adj[u][j].second;
				PQ.push(make_pair(d[v]*-1,v));
				color[v] = GRAY;
			}
		}
	}
	for(int i=0;i<n;i++){
		cout << i << " " << (d[i]==INFTY?-1:d[i]) << endl;
	}
}

int main(){
	cin >> n;
	int u,k,v,c;
	for(int i=0;i<n;i++){
		cin >> u >> k;
		for(int j=0;j<k;j++){
			cin >> v >> c;
			adj[u].push_back(make_pair(v,c));
		}
	}
	dijkstra(0);
	return 0;
}

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

typedef struct{
  int A[10001];
  int ans;
}node;
node T[10001];
int head=0;
int tail=1;
int n;

void function(int num){
  int *Q=new int[1000000];
  Q[0]=0;
  while(true){
    if(head==tail)break;
    num=Q[head++];
        if(head==999999)head=1;
    for(int i=0;i<n;i++){
      if(T[num].A[i]!=-1){
	if(T[i].ans>T[num].ans+T[num].A[i]){
	  T[i].ans=T[num].ans+T[num].A[i];
	  Q[tail++]=i;
	  	  if(tail==999999)tail=1;
	}
      }
    }
  }
  delete [] Q;
}

int main(){
  int num,son,z,w;
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      T[i].A[j]=-1;
    }
  }


  for(int i=0;i<n;i++){
    scanf("%d%d",&num,&son);
    T[num].ans=INT_MAX;
    for(int j=0;j<son;j++){
      scanf("%d%d",&z,&w);
      T[num].A[z]=w;
      }
  }

  T[0].ans=0;
  function(0);
 
  for(int i=0;i<n;i++){
      cout<<i<<" "<<T[i].ans<<endl;
  }
  return 0;
}

C++: // -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_12_B: Single Source Shortest Path I

#include <algorithm>
#include <cstdio>

using uint = unsigned int;

class Graph {
  const uint n_;
  uint* const g_;
  const uint INFINIT;
  
public:

  Graph(uint n) : n_(n), g_(new uint[(n_*n_)]), INFINIT(100000*(n_-1)+1) {
    std::fill_n(g_, (n_*n_), INFINIT);
  }

  ~Graph() { delete[] g_; }
  
  uint* operator [](uint i) const { return g_+(n_*i); }

  void dijkstra(uint* dist)
  {
    std::fill_n(dist, n_, INFINIT);
    bool visited[n_];
    std::fill_n(visited, n_, false);
    auto i = 0u; // 0-start
    visited[i] = true;
    dist[i] = 0u;
    for (auto n = 0u; n < n_-1; ++n) {
      auto cur_min = INFINIT;
      auto es = (*this)[i];
      auto base_dist = dist[i];
      for (auto j = 0u; j < n_; ++j) {
        if (visited[j]) continue;
        dist[j] = std::min(dist[j], base_dist+es[j]);
        if (cur_min > dist[j]) {
          cur_min = dist[j];
          i = j;
        }
      }
      visited[i] = true;
    }
  }
};

int main()
{
  uint n;
  std::scanf("%u", &n);

  Graph g(n);

  uint u, k, v, c;
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%u %u", &u, &k);
    for (auto j = 0u; j < k; ++j) {
      std::scanf("%u %u", &v, &c);
      g[u][v] = c;
    }
  }

  uint dist[n];
  g.dijkstra(dist);
  for (auto i = 0u; i < n; ++i) {
    std::printf("%u %u\n", i, dist[i]);
  }
}

// eof

C++: #include<iostream>
#include<algorithm>
#include<queue>

static const int MAX = 10000;
static const int INFTY = (1 << 20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

void dijkstra(int n, std::vector<std::pair<int, int> > adj) {
	std::priority_queue<std::pair<int, int> > PQ;
	int color[MAX];
	int d[MAX];
	for (int i = 0; i < n; i++) {
		d[i] = INFTY;
		color[i] = WHITE;
	}

	d[0] = 0;
	PQ.push(std::make_pair(0, 0));
	color[0] = GRAY;

	while (!PQ.empty()){
		std::pair<int, int> f = PQ.top(); PQ.pop();
		int u = f.second;
		color[u] = BLACK;

		//????°???????????????????????????????????????§???????????°??????
		if (d[u] < f.first * (-1))continue;
		
		for (size_t i = 0; i < adj[u].size(); i++) {
			int v = adj[u][i].first;
			if (color[v] == BLACK) continue;
			if (d[v] > d[u] + adj[u][i].second) {
				d[v] = d[u] + adj[u][i].second;
				//priority_queue????????????????????§??§??????????????????????????????-1????????????
				PQ.push(std::make_pair(d[v] * -1, v));
				color[v] = GRAY;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		std::cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << std::endl;
	}
}

int main() {
	std::vector<std::pair<int, int> > adj[MAX];
	int n;

	std::cin >> n;
	for (int i = 0; i < n; i++) {
		int u, k;
		std::cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v, c;
			std::cin >> v >> c;
			adj[u].push_back(std::make_pair(v, c));
		}
	}

	dijkstra(n, adj);
	
	return 0;
}