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>
using namespace std;

int main()
{
	int n, m, i, j, a, w;
	int* adj[100];
	int* dist[100];
	cin >> n;
	for(i = 0; i < n; i++){
		cin >> i >> m;
		adj[i] = new int [m + 1];
		dist[i] = new int [m + 1];
		for(j = 0; j < m; j++){
			cin >> a >> w;
			adj[i][j] = a;
			dist[i][j] = w;
		}
		adj[i][m] = -1;
		dist[i][m] = -1;
	}
	int *d, *prev, *Q;
	d = new int [n];
	prev = new int [n];
	Q = new int [n];
	for(i = 0; i < n; i++){ d[i] = 4000; prev[i] = -1; Q[i] = i; }
	int rest = n; // 0????????£???????????????Q???????????????

	int u, v, min;
	d[0] = 0;  // 0??????????????????
	while(rest > 0){
		min = 4000;
		for(i = 0; i < n; i++){
			if(min > d[i] && Q[i] >= 0){ min = d[i]; u = i; }
		}
		Q[u] = -1;  // d[u]???Q???????????????????°????d??????????????????
		rest--;	    // Q????????????-1?????????rest?????????????????????
		// u?????£??\???????????????d?????´??°???
		for(j = 0; adj[u][j] >= 0; j++){
			v = adj[u][j];
			if(d[v] > d[u] + dist[u][j]){
				d[v] = d[u] + dist[u][j];
				prev[v] = u;
			}
		}
	};
	for(i = 0; i < n; i++){ cout << i << " " << d[i] << endl; }
	for(i = 0; i < n; i++){
		delete adj[i]; delete dist[i]; }
	delete d;
	delete prev;
	delete Q;
	cin >> n;

	return 0;
}

C++: #include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define print_array(ary, size) cout << ary[0]; rep1(i, 1, size - 1) cout << ' ' << ary[i]; cout << endl;
typedef long long ll;
typedef unsigned long long ull;

int M[100][100];
int MinCost[100];
int done[100];

int main()
{
	int n, u, k, v, c;
	int next;
	int cost, sum = 0;

	cin >> n;

	rep(i, n) {
		MinCost[i] = 10000001;
		done[i] = 0;
		rep(j, n) M[i][j] = -1;
	}

	rep(i, n) {
		cin >> u >> k;
		rep(j, k) {
			cin >> v >> c;
			M[u][v] = c;
		}
	}

	MinCost[0] = 0;
	next = 0;
	done[0] = 1;
	sum = 0;
	
	rep(loop, n - 1) {
		rep(i, n) {
			if (M[next][i] != -1) {
				MinCost[i] = min(MinCost[i], MinCost[next] + M[next][i]);
			}
		}

		cost = 10000001;
		rep(i, n) {
			if (done[i] == 0 && cost > MinCost[i]) {
				cost = MinCost[i];
				next = i;
			}
		}

		done[next] = 1;
		sum += cost;
	}

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

	return 0;
}

C++: #include <bits/stdc++.h>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;
int n;
int res = 0;
struct node {
    int id;
    int dist;
    bool searched;
};

node v[100];
int edge[100][100];

int main() {
    cin >> n;
    REP(i, n) {
        int u, k;
        cin >> u >> k;
        v[u].id = u;
        v[u].dist = INF;
        v[u].searched = false;
        REP(j, n) edge[i][j] = INF;
        REP(j, k){
            int to, cost;
            cin >> to >> cost;
            edge[i][to] = cost;
        }
    }
    v[0].dist = 0;
    int next = 0;
    int prev = 0;
    REP(i, n){
        int minimum = INF;
        REP(j, n){
            if(!v[j].searched && edge[prev][j] != INF){
                v[j].dist = min(v[j].dist, v[prev].dist + edge[prev][j]);
                if(minimum >= v[j].dist){
                    next = j;
                    minimum = v[j].dist;
                }
            }
        }
        v[prev].searched = true;
        prev = next;
    }
    REP(i, n) cout << i << " " << v[i].dist << endl;
    return 0;
}

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

#define N 120
int n;

int g[N][N];

int weight[N];
bool us[N];

int prim(){

  int v;
  int ans=0;
  weight[0]=0;
  
  while(true){
    v=-1;
   
    for(int i=0;i<n;i++){
      if(us[i]!=true && (v==-1 ||weight[i]<weight[v]))v=i;
    }

    if(v==-1)break;
    us[v]=true;
    ans+=weight[v];

    for(int i=0;i<n;i++){
      if(weight[i]>(g[v][i]+weight[v])){

        weight[i]=(g[v][i]+weight[v]);
        //      cout <<"fsafa"<<endl;
      }
    }
  }
  return ans;
}


int main(){

  int u,k1,c,v;

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      g[i][j]=53535;
    }
  }

//load n
  cin >>n;

  //load data
  for(int i=0;i<n;i++){
    weight[i]=INT_MAX;
    us[i]=false;
    scanf("%d %d",&u,&k1);
    for(int j=0;j<k1;j++){
      scanf("%d %d",&v,&c);
      g[u][v]=c;
      //    cout <<g[i][j]<<" ";
    }
    //    cout <<endl;
  }




  //print
  prim();

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

}