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 <iostream>
#include <queue>
#include <vector>

struct Edge {
  int dst;
  long long cost;
  Edge() {}
  Edge(int x, long long y) : dst(x), cost(y) {}
};

std::vector<long long> dijkstra(int sv, std::vector<std::vector<Edge>> &G) {
  const long long LINF = 1000000000000000018LL;

  int n = (int)G.size();
  std::vector<long long> dist(n, LINF);
  dist[sv] = 0;

  typedef std::pair<long long, int> PLI;
  std::priority_queue<PLI, std::vector<PLI>, std::greater<PLI>> que;

  que.push(std::make_pair(0LL, sv));

  while (!que.empty()) {
    PLI now = que.top();
    que.pop();
    long long cur_d = now.first;
    long long cur_v = now.second;

    if (dist[cur_v] < cur_d) {
      continue;
    }

    for (int i = 0; i < (int)G[cur_v].size(); i++) {
      int next_v = G[cur_v][i].dst;
      long long cost = G[cur_v][i].cost;
      if (dist[cur_v] + cost < dist[next_v]) {
        dist[next_v] = dist[cur_v] + cost;
        que.push(std::make_pair(dist[next_v], next_v));
      }
    }
  }
  return dist;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<std::vector<Edge>> g(n);
  for (int i = 0; i < n; i++) {
    int u;
    std::cin >> u;
    int k;
    std::cin >> k;
    while (k--) {
      int v, c;
      std::cin >> v >> c;
      g[u].push_back(Edge(v, c));
    }
  }

  std::vector<long long> dist = dijkstra(0, g);
  for (int i = 0; i < n; i++) {
    std::cout << i << " " << dist[i] << std::endl;
  }

  return 0;
}

C++: //ALDS1_12_cにて、AC
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int main(){
  int n;
  cin>>n;
  vector<pair<int,int> > adj[10005]; //重み付き有向グラフの隣接リスト表現
  //隣接リストの作成
  int u,k;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v,c;
      cin>>v>>c;
      adj[u].emplace_back(v,c);
    }
  }

  //ここからダイクストラ
  priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > pq;
  vector<bool> fg(n+1000);
  vector<int> cost(n+1000);
  //初期化
  for(int i=0;i<n;i++){
    cost[i]=INF;
    fg[i]=false;
  }
  //出発地点はコスト0
  cost[0]=0;
  pq.emplace(0,0);
 
  //最短経路を検出
  while(!pq.empty()){
    auto now=pq.top(); pq.pop();
    int u=now.second;
    fg[u]=true;

    //最小値を取り出し、それが最短でなければ無視
    if(cost[u]<now.first) continue;
    
    //次の辺へ移動
    for(int j=0;j<adj[u].size();j++){
      int v=adj[u][j].first;
      if(fg[v]) continue;
      if(cost[v]>cost[u]+adj[u][j].second){
        cost[v]=cost[u]+adj[u][j].second;
        //priority_queueはデフォルトで大き値を優先するため、-1をかける。
        pq.emplace(cost[v],v);
      }
    }
  }

  for(int i=0;i<n;i++){
    cout<<i<<" "<<(cost[i]==INFINITY ? -1 : cost[i])<<'\n';
  }
  return(0);
}

C++: #include<cstdio>
#include<stdlib.h>
#include<iostream>

using namespace std;

const int maxn = 105;
int M[maxn][maxn];
int d[maxn];
int p[maxn];
bool visit[maxn];

int main(){
	int n;
	int u,k,v,c;
	cin >> n;
	for(int i = 0;i < n;i++){
		visit[i] = false;
		d[i] = 0x3f3f3f;
		for(int j = 0;j < n;j++){
			M[i][j] = -1;
		}
	}
	
	for(int i = 0;i < n;i++){
		cin >> u >> k;
		for(int j = 0;j < k;j++){
			cin >> v >> c;
			M[u][v] = c;
		}
	}
	
	d[0] = 0;
	int result = 0;
	while(true){
		int u;
		int min_distance = 0x3f3f3f;
		for(int i = 0;i < n;i++){
			if(visit[i])continue;
			if(d[i] < min_distance){
				min_distance = d[i];
				u = i;
			}
		}
		if(min_distance == 0x3f3f3f)break;
		visit[u] = true;
		result += min_distance;
		for(int i = 0;i < n;i++){
			if(visit[i])continue;
			if(M[u][i] == -1)continue;
			if(d[u] + M[u][i] < d[i]){
				d[i] = d[u] + M[u][i];
				p[i] = u;
			}
		}
	}
	for(int i = 0;i < n;i++)cout << i << " " << d[i] << endl;
//	cout << result << endl;
	
}

C++: #include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;


ll M[110][110]; //edge weight
ll color[110];
ll white = 0, gray = 1, black = 2;
ll n; 

void dijkstra(){
  ll d[110];//d[v] vまでの最短経路
  ll minv;
  rep(i, 0, n){
    color[i] = white;
    d[i] = INF;
  }
  d[0] = 0;
  color[0] = gray;
  while(1){
    minv = INF;
    ll u = -1;
    rep(i, 0, n){
      if(minv > d[i] && color[i] != black){// はじめd[i]=0, u = 0, minv = 0
        u = i;
        minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = black;// 最も重さが小さいほうへすすむ
    rep(v, 0, n){
      if(color[v] != black && M[u][v] != INF){
        if(d[v] > d[u] + M[u][v]){
          d[v] = d[u] + M[u][v]; //d[v]を更新
          color[v] = gray;
        }
      }
    }
  }
  rep(i, 0, n){
    cout << i << " " << d[i] << endl;
  }
}

int main() {
  cin >> n;
  rep(i, 0, n){//始めに辺の重さをマックスに初期化
    rep(j, 0, n) M[i][j] = INF;
  }

  rep(i, 0, n){
    ll u; cin >> u;
    ll k; cin >> k;
    rep(j, 0, k){
      ll v, c; cin >> v >> c;
      M[u][v] = c;//辺の重さを入力
    }
  }

  dijkstra();

  return 0;
}