Go: package main

import (
	"bufio"
	"fmt"
	"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() {
	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++: /*???????????????????????¢?????´???????????§?????????????°???¨??????????????????????????¢?´¢??????*/
/*????????????????????\????????¨???????????¨??§???????????????O((|E|+|V|)log|V|)?????§??????*/
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep0(i,i0,n) for(int i = i0;i<=n;i++)
using namespace std;
#define inf (1<<20)
#define MAX 100000

static const int White=0;
static const int Gray=1;
static const int Black=2;

int n;
vector<pair<int, int> > adj[MAX]; //??£??\?????????

void Dijkstra(){
    priority_queue<pair<int, int> > PQ;
    int color[MAX];
    int D[MAX];
    rep(i, n){
        D[i]=inf;
        color[i]=inf;
    }
    D[0]=0;
    PQ.push(make_pair(0, 0));
    color[0]=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;

        rep(j, adj[u].size()){
            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;
            }
        }
    }

    rep (i,n) cout << i << " " << ( D[i] == inf ? -1 : D[i]) << endl;
}

int main(void){
    int k,u,v,c;
    cin >> n;

    rep(i, n){
        cin >> u >>k;
        rep(j, k){
            cin >> v >> c;
            adj[u].push_back(make_pair(v, c));
        }
    }

    Dijkstra();

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1000 * 100000;

int main(void){
  int n;
  cin >> n;
  vector< vector<pair<int, int> > > g(n);
  for(int i=0; i < n; i++){
    int v; cin >> v;
    int k; cin >> k;
    for(int j=0; j < k; j++){
      int v0, c; cin >> v0 >> c;
      g[v].push_back(make_pair(v0, c));
    }
  }
  vector<ll> d(n, INF);
  vector<bool> used(n, false);
  priority_queue<pair <int, int> > pq;
  d[0] = 0;

  pq.push(make_pair(0, 0));

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

    for(int i=0; i < g[u].size(); i++){
      int v = g[u][i].first;
      if(used[v] == true) continue;
      if(d[v] > d[u] + g[u][i].second){
        d[v] = d[u] + g[u][i].second;
        pq.push(make_pair(d[v] * (-1), v));
      }
    }
  }
  for(int i=0; i < n; i++){
    cout << i << " " << d[i] << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#define MAX 100
#define INF (1<<30)

using namespace std;
enum state{
  BLACK,
  WHITE
};

int main(){
  vector<int> v[MAX];
  vector<int> c[MAX];
  state s[MAX];
  int d[MAX];
  int n; cin>>n;

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

  for(int i=0;i<n;i++){
    s[i] = WHITE;
    d[i] = INF;
  }
  s[0]=BLACK;
  d[0]=0;

  vector<int> blacklist;
  blacklist.push_back(0);

  while(1){
    int& last = blacklist.back();
    for(int i = 0;i<v[last].size();i++){
      if(d[v[last][i]]>d[last]+c[last][i]){
        d[v[last][i]]=d[last]+c[last][i];
      }
    }

    int minv=-1;
    int mind=INF;
    for(int b:blacklist){
      for(int i=0;i<v[b].size();i++){
        if(s[v[b][i]]!=BLACK && d[v[b][i]]<mind){
          minv=v[b][i];
          mind=d[v[b][i]];
        }
      }
    }
    if(minv!=-1){
      s[minv]=BLACK;
      blacklist.push_back(minv);
    }else{
      break;
    }
  }

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