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 <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;

#define M 10005
#define INF 0x3f3f3f3f

int d[M][M],a[M],n;
bool vis[M];

void dijkstra()
{
    printf("%d!\n",n);
    for(int i=0;i<n;i++){
        if(i == 0) a[i]=0;
        else a[i]=INF;
    }
    memset(vis,0,sizeof(vis));
    for(int i=0;i<n;i++){
        int mark=-1,minn=INF;
        for(int j=0;j<n;j++){
            if(!vis[j]&&a[j]<minn){
                minn=a[j];
                mark=j;
            }
        }
        vis[mark]=1;
        for(int j=0;j<n;j++){
            if(!vis[j]){
                a[j]=min(a[j],a[mark]+d[mark][j]);
            }
        }
    }
    for(int i=0;i<n;i++){
        printf("%d %d\n",i,a[i]);
    }
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(j == i)
                d[i][j]=0;
            else
                d[i][j]=INF;
        }
    }
    for(int j=0;j<n;j++){
        int u,k;
        scanf("%d%d",&u,&k);
        for(int i=0;i<k;i++){
            int v,w;
            scanf("%d%d",&v,&w);
            d[u][v]=w;
        }
    }
    dijkstra();
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

#define MAX_V 100

struct edge {
	edge(int a, int b) {
		cost = a;
		to = b;
	}
	int cost;
	int to;
};

int n;
vector<vector<edge>> G;
vector<int> d;

void dijkstra(int s) {
	priority_queue<pii, vector<pii>, greater<pii>> que;
	d[s] = 0;
	que.push(pii(0, s));

	while (!que.empty()) {
		pii 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(pii(d[e.to], e.to));
			}
		}
	}

}

int main() {
	int n,u,k,tmpp,tmpw;
	cin >> n;
	d = vector<int>(n, INF);
	G = vector<vector<edge>>(n);
	rep (i,n) {
		cin >> u >> k;
		rep(j, k) {
			cin >> tmpp>>tmpw;
			G[u].emplace_back(tmpw, tmpp);
		}
	}
	dijkstra(0);
	rep(i, n) {
		cout << i << " " << d[i] << endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <bitset>

using namespace std;

int main()
{
	int N;
	cin>>N;
	
	vector<vector<int> > cost(N,vector<int>(N,10000001));
	cost[0][0]=0;
	pair<int,int> ddata;
	for(int i=0;i<N;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			cin>>ddata.first>>ddata.second;
			cost[u][ddata.first]=ddata.second;
		}
	}
	//
	
	vector<int> maxcost(N,10000001);
	
	priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > que;
	
	que.push(pair<int,int>(0,0));
	
	while(!que.empty()){
		int n=que.top().second;
		if(que.top().first<maxcost[n]){
			maxcost[n]=que.top().first;
		}
		for(int j=1;j<N;j++){
			if(que.top().first+cost[n][j]<maxcost[j]){
				maxcost[j]=que.top().first+cost[n][j];
				ddata.first=que.top().first+cost[n][j];
				ddata.second=j;
				que.push(ddata);
			}
		}
		que.pop();
	}
	
	for(int i=0;i<N;i++){
		cout<<i<<' '<<maxcost[i]<<endl;
	}
	return 0;
}