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++: #include<iostream>
#include<vector>
#include<queue>
#include <bitset>
using namespace std;
template< typename FirstType, typename SecondType >
struct PairComparator {
  bool operator()( const pair<FirstType, SecondType>& p1, const pair<FirstType, SecondType>& p2 ) const 
    {  
		return p1.first > p2.first;
    }
};
bool inMST(vector< std::pair<int,int> > & MST,int j) {
	for (int k=0;k<(int)MST.size();++k){
		if(j == MST[k].second)
			return true;
	}
	return false;
}
int main(){
	int n;
	cin >> n;
	//vector<int> E(n*n,-1);
	vector<vector<pair<int,int> > > edge(n);
	vector<int> DPG(n,-1);
	vector< std::pair<int,int> > MST;
	std::bitset<10000> flg;

	{
		for(int j=0;j<n;++j) {
			int u,k; 
			cin >> u >> k;
			edge[u].resize(k);
			for(int i=0;i<k;++i){
				int v,c;
				cin >> v >> c;
				edge[u][i] = make_pair(v,c);
			}
		}
	}
	priority_queue<pair<int,pair<int,int> >,vector< pair<int,pair<int,int> > >,
		PairComparator<int,pair<int,int> > > r;

	int cost = 0;
	int i=0;
	MST.push_back(pair<int,int>(i,i));
	flg.set(i);
	DPG[i] = 0;
	while((int)MST.size() < n) {
		int ii=i*n;
//		for (int j=0;j<n;++j) 
		for (int p=0;p<(int)edge[i].size();++p)
		{
			pair<int,int> add = std::make_pair(i,edge[i][p].first);
//			if (!inMST(MST,add.second))
			if (!flg.test(edge[i][p].first))
			{
				r.push(std::pair<int,std::pair<int,int> >(edge[i][p].second+DPG[i],add));
			}
		}
		pair<int,pair<int,int> > top;
		while (!r.empty()) {
			top = r.top();
			r.pop();
//			if (!inMST(MST,top.second.second))
			if (!flg.test(top.second.second))
			{
				break;
			}
		}
		cost += top.first;
		MST.push_back(top.second);
		flg.set(top.second.second);
		i = top.second.second;
		DPG[i] = top.first;
//		for(int j=0;j<n;++j)
		for (int p=0;p<(int)edge[i].size();++p)
		{
			int j = edge[i][p].first;
			if (DPG[j] < 0)continue;
			DPG[j] = std::min(DPG[j],DPG[i] + edge[i][p].second);
		}
	}
	for (int j=0;j<n;++j) {
		cout << j << " " <<  DPG[j] << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using vll = vector<ll>;
using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

//pow(llpow,modpow)
template <class T>
ll llpow(ll x, T n)
{
    ll ans = 1;
    if (x == 0)
        ans = 0;
    while (n)
    {
        if (n & 1)
            ans *= x;
        x *= x;
        n >>= 1;
    }
    return ans;
}
long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
template <class T>
inline T gcd(T x, T y)
{
    if (y == 0)
        return x;
    else
    {
        return gcd(y, x % y);
    }
}
//最小公倍数
template <class T>
inline T lcm(T x, T y) { return x / gcd(x, y) * y; }
//逆元
long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
#define white 0
#define gray 1
#define black 2

long long INF = 1LL << 60;
int main()
{
    int n;
    cin >> n;
    vector<pii> t[n];
    using plli = pair<ll, int>;
    rep(i, 0, n)
    {
        int u, k;
        cin >> u;
        cin >> k;
        rep(j, 0, k)
        {
            int v, c;
            cin >> v >> c;
            pii in = make_pair(v, c);
            t[u].push_back(in);
        }
    }
    vi state(n,white);
    vector<int> res(n, 1<<30);
    res[0]=0;
    priority_queue<plli, vector<plli>, greater<plli>> q; //cost,index
    q.emplace(0, 0);
    rep(i, 1, n)
    {
        q.emplace(1 << 30, i);

    }
    while (!(q.empty()))
    {
        pii node = q.top();
        q.pop();
        int index = node.second;
        int v = node.first;
        state[index]=black;
        if(res[index]<v)continue;
        res[index]=v;
        for (pii to : t[index])
        {
            if (state[to.first] != black && to.second + v < res[to.first] )
            {
                state[to.first]=gray;
                res[to.first]=to.second+v;
                q.emplace(res[to.first],to.first);
            }
        }
    }
    rep(i, 0, n) cout << i << " " << res[i] << endl;
    return 0;
}