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<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
vector<vector<P> > G;
signed main(){
  int n;
  cin>>n;
  int INF=1LL<<55LL;
  G.resize(n);
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v,c;
      cin>>v>>c;
      G[u].push_back(P(v,c));
    }
  }
  int d[n];
  for(int i=0;i<n;i++) d[i]=INF;
  d[0]=0;

  priority_queue<P,vector<P>,greater<P> > q;
  d[0]=0;
  q.push(P(0,0));

  while(!q.empty()){
    P p=q.top();q.pop();
    int u=p.second,c=p.first;
    //cout<<u<<" "<<c<<endl;
    if(d[u]<c) continue;
    for(P e:G[u]){
      int v=e.first,w=e.second;
      if(d[v]>d[u]+w){
	d[v]=d[u]+w;
	q.push(P(d[v],v));
	//cout<<v<<":"<<d[v]<<endl;
      }
    }
  }
  
  for(int i=0;i<n;i++) cout<<i<<" "<<d[i]<<endl;
  return 0;
}

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

using namespace std;

#define N 10000

#define WHITE 0
#define GRAY 1
#define BLACK 2

static const int INFTY = (1<<20);
int n;

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

void dijkstra(void);

int main(void){
  int i,j,k;
  int u, v, c;

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

  dijkstra();

  return 0;
}




void dijkstra(void){
  priority_queue<pair<int,int> >PQ;
  int i,j;
  int u,v;
  int d[N],color[N];
  
  for(i = 0;i < n;i++){
    color[i] = WHITE;
    d[i] = INFTY;
  }

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

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

    if(d[u] < f.first*(-1)){
      continue;
    }

    for(j = 0;j < adj[u].size();j++){
      v = adj[u][j].first;
      
      if(color[v] == BLACK){
	continue;
      }
      
      if(d[v] > d[u] + adj[u][j].second){
	color[v] = GRAY;
	d[v] = d[u] + adj[u][j].second;
	PQ.push(make_pair(d[v]*(-1),v));
	
      }
    }
    
  }

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

C++: #include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

struct Node {
    int pos;
    int sum_cost;

    Node(int p, int c) {
        pos = p;
        sum_cost = c;
    }

    bool operator >(const Node &other) const {
        return sum_cost > other.sum_cost;
    }
};

struct Edge {
    int to_node;
    int cost;

    Edge(int n, int c) {
        to_node = n;
        cost = c;
    }
};

vector<vector<Edge>> adj; // 隣接行列
priority_queue<Node, vector<Node>, greater<Node>> pq; // ヒープ
int dist[10100];

int main() {
    int n; cin >> n;
    adj.resize(n);
    rep(i, n) {
        int u, k; cin >> u >> k;
        rep(j, k) {
            int v, c; cin >> v >> c;
            adj[u].emplace_back(Edge(v, c));
        }
    }

    // 初期化
    rep(i, n) {
        dist[i] = (i == 0) ? 0 : INT_INF;
        pq.push(Node(i, dist[i]));
    }

    while (!pq.empty()) {
        Node popped = pq.top();
        pq.pop();

        for (auto &edge: adj[popped.pos]) {
            Node next(edge.to_node, popped.sum_cost + edge.cost);
            if (next.sum_cost < dist[edge.to_node]) {
                pq.push(next);
                dist[edge.to_node] = next.sum_cost;
            }
        }
    }

    rep(i, n) {
        cout << i << ' ' << dist[i] << endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
static const int M = 10000;

int n;
vector<pair<int,int> > a[M];

void dijkstra(void);

int main(){
  int x,y,z,w,i,j;

  cin >> n;
  for(i = 0;i < n;i++){
    cin >> x >> y;
    for(j = 0;j < y;j++){
      cin >> z >> w;
      a[x].push_back(make_pair(z,w));
    }
  }
  dijkstra();

  return 0;
}

void dijkstra(void){
  priority_queue<pair<int,int> > PQ;
  int color[M],d[M],i,j,x,z;

  for(i = 0;i < n;i++){
    d[i] = 10000000;
    color[i] = 0; //0=white
  }
  d[0] = 0;
  PQ.push(make_pair(0,0));
  color[0] = 1; //1=gray

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

    for(j = 0;j < a[x].size();j++){
      z = a[x][j].first;
      if(color[z] == 2) continue;
      if(d[z] > d[x] + a[x][j].second){
	d[z] = d[x] + a[x][j].second;
	PQ.push(make_pair(d[z] * (-1),z));
	color[z] = 1;
      }
    }
  }
  for(i = 0;i < n;i++){
    cout << i << " " << (d[i] == 10000000 ? -1 : d[i]) << endl;
  }
}