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{0}, shortestList, adjacentMatrix)
	for _, v := range shortestList {
		fmt.Printf("%d %d\n", v.getEnd(), v.shortest)
	}
}

func (si ShortestInfo) getEnd() int {
	if len(si.edges) == 0 {
		return 0
	} 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]
}

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] = shortestInfo
}

func findAdjacents(currentNode int, adjacentMatrix [][]int) []Edge {
	adjacents := adjacentMatrix[currentNode]
	edges := []Edge{}
	for i, v := range adjacents {
		if v >= 0 {
			edges = append(edges, Edge{start: currentNode, end: i, weight: v})
		}
	}
	return edges
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
vector<vector<P> > G;
signed main(){
  int n;
  cin>>n;
  int INF=1LL<<55LL;
  G.resize(n);
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v,c;
      cin>>v>>c;
      G[u].push_back(P(v,c));
    }
  }
  int d[n];
  for(int i=0;i<n;i++) d[i]=INF;
  d[0]=0;

  priority_queue<P,vector<P>,greater<P> > q;
  d[0]=0;
  q.push(P(0,0));

  while(!q.empty()){
    P p=q.top();q.pop();
    int u=p.second,c=p.first;
    //cout<<u<<" "<<c<<endl;
    if(d[u]<c) continue;
    for(P e:G[u]){
      int v=e.first,w=e.second;
      if(d[v]>d[u]+w){
	d[v]=d[u]+w;
	q.push(P(d[v],v));
	//cout<<v<<":"<<d[v]<<endl;
      }
    }
  }
  
  for(int i=0;i<n;i++) cout<<i<<" "<<d[i]<<endl;
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<utility>

#define INF 9999999999

using namespace std;

const int MAX_N = 100000;

int d[MAX_N];

struct edge{
	int to;   //?????????
	int cost; //?????????
};

typedef pair<int,int>P;

void dijkstra(int s,int n)
{
	int k,l,p,q,r,u,v,cost,m;
	vector<edge> edgelist[n];
	for(int i=0;i<n;i++){
		scanf("%d",&u);
		scanf("%d",&m);
		for(int j=0;j<m;j++){
			edge e;
			scanf("%d",&v);
			scanf("%d",&cost);
			e.to = v;	e.cost = cost;
			edgelist[i].push_back(e);
		}
	}
	priority_queue<P,vector<P>,greater<P> > que;
	d[s] = 0;
	que.push(P(0,s));
	while(!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		vector<edge>::iterator it = edgelist[v].begin();
		while(it != edgelist[v].end()){
			if(d[it->to] > d[v] + it->cost){
				d[it->to] = d[v] + it->cost;
				que.push(P(d[it->to],it->to));
			}
			it++;
		}
	}
}

int main()
{
	int k,l,m,n,s;
	scanf("%d",&n); // ?????°?????\???
	fill(d,d+n,INF);
	dijkstra(0,n);
	for(int i=0;i<n;i++){
		printf("%d %d\n",i,d[i]);
	}
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e5) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

struct UF {
    static const int MAX_N = 100000;
    int p[MAX_N];
    int r[MAX_N];

    void init(int n) {
        REP(i, n) {
            p[i] = i;
            r[i] = 0;
        }
    }
    int find(int x) {
        if (p[x] == x) return x;
        return p[x] = find(p[x]);
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (r[x] < r[y]) swap(x, y);
        if (r[x] == r[y]) r[x]++;
        p[y] = x;
    }
    bool same(int x, int y) { return find(x) == find(y); }
};

int n, d[100000];
vector<P> g[100000];

void dijkstra(int s) {
    fill(d, d + n, 99999999*2);
    d[s] = 0;
    priority_queue<P> que;
    que.push({0, s});
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int u = p.second;
        if (p.first > d[u]) continue;
        REP(i, g[u].size()) {
            int v = g[u][i].first, cost = g[u][i].second;
            if (d[v] > d[u] + cost) {
                d[v] = d[u] + cost;
                que.push({d[v], v});
            }
        }
    }
}

int main() {
    cin >> n;
    REP(i, n) {
        int from, k;
        cin >> from >> k;
        REP(j, k) {
            int to, c;
            cin >> to >> c;
            g[from].push_back({to, c});
        }
    }
    dijkstra(0);
    REP(i, n) { cout << i << " " << d[i] << endl; }
    return 0;
}