Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
type Node struct {
	cost int
	done bool
}

type Edge struct {
	to, cost int
}

const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	nodes := make([]Node, N)
	for i := 0; i < N; i++ {
		nodes[i].cost = INF
	}
	E := make([][]Edge, N)
	for i := 0; i < N; i++ {
		id, k := sc.nextInt(), sc.nextInt()
		for j := 0; j < k; j++ {
			to, cost := sc.nextInt(), sc.nextInt()
			E[id] = append(E[id], Edge{to, cost})
		}
	}
	nodes[0].cost = 0
	for {
		cur := 0
		minCost := INF
		for i := 0; i < N; i++ {
			n := nodes[i]
			if !n.done && n.cost < minCost {
				cur = i
				minCost = n.cost
			}
		}
		if minCost == INF {
			break
		}
		nodes[cur].done = true
		for i := 0; i < len(E[cur]); i++ {
			to, cost := E[cur][i].to, E[cur][i].cost+nodes[cur].cost
			if !nodes[to].done && cost < nodes[to].cost {
				nodes[to].cost = cost
			}
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprintln(wtr, i, nodes[i].cost)
	}
	wtr.Flush()
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define pb push_back
#define fi first
#define se second

#define MAX_V 110
#define INF 1e9

struct edge{int to,cost;};
typedef pair<int,int> P;
int d[MAX_V];
int V;
vector<edge> G[MAX_V];

edge makeedge(int t,int c){
    edge e;
    e.to=t;
    e.cost=c;
    return e;
}

void addedge(int s,int t,int c){
    G[s].push_back(makeedge(t,c));
    //G[t].push_back(makeedge(s,cost));
}

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push(P(0,s)); 

    while(!que.empty()){
        P p=que.top(); que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        for(int i=0;i<G[v].size();i++){
            edge &e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}


int main(){
    int i,j,n;
    cin>>n;
    V=n;
    int u,k;
    int x,y;
    for(i=0;i<n;i++){
        cin>>u>>k;
        for(j=0;j<k;j++){
            cin>>x>>y;
            addedge(i,x,y);
        }
    }
    dijkstra(0);
    for(i=0;i<n;i++){
        cout<<i<<" "<<d[i]<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>

using namespace std;

class SSSPath
{
public:
  vector<int> v;
  int solve();
};

int SSSPath::solve()
{
  int n;
  cin >> n;

  const int infty = 20000;
  vector<int> d( n, infty );
  
  d[0] = 0;

  vector<vector<int>> adj( n, vector<int>( n, -1 ) );


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

  vector<int> sv( n, true );

  while ( true )
    {
      int md = infty;
      int u;
      
      for ( auto i = 0; i < n; ++i )
        {
          if ( sv[i] && d[i] < md )
            {
              u = i;
              md = d[i];
            }
        }

      if ( md == infty ) break;

      sv[u] = false;
      
      for ( auto i = 0; i < n; ++i )
        {
          if ( sv[i] && adj[u][i] >= 0 )
            {
              if ( d[u] + adj[u][i] < d[i] )
                {
                  d[i] = d[u] + adj[u][i];
                  
                }
            }
          
        }
    }

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

int main()
{
  SSSPath s;

  s.solve();

  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