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<queue>
#include<algorithm>
#include<cstring>
 
using namespace std;
 
typedef pair<int,int>pii;
#define INF 0x3f3f3f3f
#define fi first
#define se second
 
int mcos[10005];
vector <pii> G[1000005];
int N;
 
 
void dijkstra(int start){
  priority_queue<pii,vector<pii>,greater<pii> > pq;
 
  pq.push( pii(0,start) );
  memset( mcos,INF,sizeof(mcos));
  mcos[start]=0;
 
   
  while(!pq.empty() ){
    const pii tmp=pq.top();
    pq.pop();
     
    const int now=tmp.se;
     
    if(mcos[now] < tmp.fi) continue;
     
    for(int i=0;i<G[now].size();++i){
      const int newcost = G[now][i].fi + tmp.fi;
      const int next= G[now][i].se;
       
      if(newcost < mcos[next] ){
    mcos[next]=newcost;
    pq.push( pii(newcost,next) );
      }
    }
  }
  return ;
   
}
 
int main (){
  cin>>N;
  int k,u,v,c;
 
  for(int i=0;i<N;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v>>c;
      G[u].push_back(make_pair(c,v));
    }
  }
  dijkstra(0);
  for(int i=0;i<N;i++){
    cout<<i<<" "<<mcos[i]<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long signed int ll;

constexpr ll NIL = -20000000000;

class path{
public:
    int from;
    int to;
    int dist;
    path(){
        from = -1;
        to = -1;
        dist = -1;
    }
    path(int from_,int to_,int dist_){
        from = from_;
        to = to_;
        dist = dist_;
    }
    static bool compare(const path& a,const path& b) {
        return a.from < b.from;
    }
    bool operator<(const path& e) const {
        return this->dist < e.dist;
    }
};

int n,u,k,v,c;
vector<path> w;
ll d[10000];
bool dd[10000];

int main() {
    for(int i = 0;i < 10000;i++)d[i] = -NIL;
    for(int i = 0;i < 10000;i++)dd[i] = false;
    cin >> n;
    for(int i = 0;i < n;i++) {
        cin >> u >> k;
        for(int j = 0;j < k;j++) {
            cin >> v >> c;
            w.push_back(path(u,v,c));
        }
    }
    sort(w.begin(),w.end(),path::compare);
    priority_queue<pair<int,int>> q;
    q.push(make_pair(0,0));
    d[0] = 0;
    while(!q.empty()) {
        auto y = q.top();q.pop();
        if(dd[y.second]) continue;
        auto r = lower_bound(w.begin(),w.end(),path(y.second,0,0),path::compare);
        auto l = lower_bound(w.begin(),w.end(),path(y.second+1,0,0),path::compare);
        for(auto itr = r;itr < l;itr++) {
            if(d[itr->to] > d[itr->from] + itr->dist) {
                d[itr->to] = d[itr->from] + itr->dist;
                q.push(make_pair(d[itr->to],itr->to));
            }
        }
    }
    for(int i = 0;i < n;i++){
        cout << i << " " << d[i] << endl;
    }
}

C++: #include<queue>
#include<vector>
#include<utility>
#include<functional>

namespace ProconLib{
    template<class graph_t,typename cost_t,cost_t INF=cost_t(1e15)>
    std::vector<cost_t> Dijkstra(int s,const graph_t& g){
        int n=g.size();
        std::vector<cost_t> res(n,INF);
        std::vector<char> used(n,0);
        res[s]=0;
        std::priority_queue<std::pair<cost_t,int>,std::vector<std::pair<cost_t,int>>,std::greater<>> que;
        que.push(std::make_pair(cost_t(0),s));
        while(!que.empty()){
            auto p=que.top(); que.pop();
            cost_t dist=p.first;
            int v=p.second;
            if(used[v]) continue;
            used[v]=true;
            for(int i=0;i<g[v].size();i++){
                cost_t tdist=dist+g[v][i].weight;
                if(tdist<res[g[v][i].to]){
                    res[g[v][i].to]=tdist;
                    que.push(std::make_pair(tdist,g[v][i].to));
                }
            }
        }
        return res;
    }

    // using Weight=long long;
    // struct Edge{
    //     int to;
    //     Weight weight;
    // };
    // using Edges=vector<Edge>;
    // using Graph=vector<Edges>;
}
// AOJ(ALDS1_12_C)
#include<iostream>
using namespace std;
using namespace ProconLib;
using Weight=long long;
struct Edge{
    int to;
    Weight weight;
};
using Edges=vector<Edge>;
using Graph=vector<Edges>;
int main(){
    int n;
    cin>>n;
    Graph g(n);
    for(int i=0;i<n;i++){
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;j++){
            Edge e;
            cin>>e.to>>e.weight;
            g[u].push_back(e);
        }
    }
    auto d=Dijkstra<Graph,Weight>(0,g);
    for(int i=0;i<n;i++){
        cout<<i<<" "<<d[i]<<endl;
    }

    return 0;
}