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++: //ALDS1_12_cにて、AC
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int main(){
  int n;
  cin>>n;
  vector<pair<int,int> > adj[10005]; //重み付き有向グラフの隣接リスト表現
  //隣接リストの作成
  int u,k;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v,c;
      cin>>v>>c;
      adj[u].emplace_back(v,c);
    }
  }

  //ここからダイクストラ
  priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > pq;
  vector<bool> fg(n+1000);
  vector<int> cost(n+1000);
  //初期化
  for(int i=0;i<n;i++){
    cost[i]=INF;
    fg[i]=false;
  }
  //出発地点はコスト0
  cost[0]=0;
  pq.emplace(0,0);
 
  //最短経路を検出
  while(!pq.empty()){
    auto now=pq.top(); pq.pop();
    int u=now.second;
    fg[u]=true;

    //最小値を取り出し、それが最短でなければ無視
    if(cost[u]<now.first) continue;
    
    //次の辺へ移動
    for(int j=0;j<adj[u].size();j++){
      int v=adj[u][j].first;
      if(fg[v]) continue;
      if(cost[v]>cost[u]+adj[u][j].second){
        cost[v]=cost[u]+adj[u][j].second;
        pq.emplace(cost[v],v);
      }
    }
  }

  for(int i=0;i<n;i++){
    cout<<i<<" "<<(cost[i]==INF ? -1 : cost[i])<<'\n';
  }
  return(0);
}

C++: #include <stdio.h>
#include <queue>
#include <vector>
#include <functional>

#define N 100
#define INF 100000000
#define MIN(a,b) ((a>b)?(b):(a))

using namespace std;


class list {
public:
	int cost;
	int node;
	int from;
	list(void) {
		cost = -1;
		node = -1;
		from = -1;
	}
};

bool operator<(const list& y,const list& x) {
	return (y.cost < x.cost);
};
bool operator>(const list& y,const list& x) {
	return (y.cost>x.cost);
};

list m[N][N];
bool visited[N];
int sum = 0;
int dist[N];

int main(void) {
	priority_queue<list, vector<list>, greater<list> > pq;
	int n;
	int now;
	int work;
	int k[N];
	int u;
	scanf("%d", &n);
	for (int i = 0; i<n; i++) {
		visited[i] = false;
		dist[i] = INF;
		scanf("%d", &u);
		scanf("%d", &k[u]);
		for (int j = 0; j < k[u]; j++) {
			int a, b;
			scanf("%d", &a);
			scanf("%d", &b);
			m[u][j].cost = b;
			m[u][j].node = a;
		}
	}
	now = 0;
	dist[now] = 0;
	while (1) {
		//printf("I'm in %d\n", now);
		bool f = visited[now];
		visited[now] = true;
		for (int j = 0; j<k[now] && !f; j++) {
				list a;
				a.cost = m[now][j].cost;
				a.node = m[now][j].node;
				a.from=now;
				pq.push(a);
				//printf("I pushed %d %d\n", a.node, a.cost);
		}
		//system("pause");
		list x;
		while (!pq.empty()) {
			if (visited[(pq.top()).node] == false || visited[(pq.top()).node]==true) {
				x = pq.top();
				//printf("I got %d %d %d %d\n", x.node, x.cost,sum,x.from);
				pq.pop();
				now = x.node;
				sum += x.cost;
				dist[now] = MIN(dist[x.from]+x.cost,dist[now]);
				break;
			}
			else pq.pop();
		}
		if (x.node == -1)break;
	}
	for (int i = 0; i < n; i++) printf("%d %d\n", i, dist[i]);
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+7;
const int INF = 1e6+7;
vector<pair<int, int> > adj[MAXN];
priority_queue<pair<int, int> > q;

int d[MAXN];
bool visit[MAXN];
int n;
set<int> s;
void djas() {
    d[0] = 0;
    for(int i = 1; i < n; i++) {
        d[i] = INF;
    }
    q.push(make_pair(0, 0));
    while(!q.empty()) {
        pair<int, int> s1 = q.top(); q.pop();
        int u = s1.second;
        visit[u] = true;
        for(int j = 0; j < adj[u].size(); j++) {
            int v = adj[u][j].second;
            if(visit[v]==false) {
                if(d[v]>d[u]+adj[u][j].first) {
                    d[v] = d[u]+adj[u][j].first;
                    q.push(make_pair((-1)*d[v],v));
                }
            }
        }
    }
}
int main() {
//    freopen("in.txt", "r", stdin);
    memset(visit, false, sizeof(visit));
    scanf("%d", &n);
    int v;
    int c;
    int id;
    int degree;
    for(int i = 0; i < n; i++) {
        scanf("%d", &id);
        scanf("%d", &degree);
        for(int j = 0; j < degree; j++) {
            scanf("%d", &v);
            scanf("%d", &c);
            adj[id].push_back(make_pair(c,v));
        }
    }
    djas();
    for(int i = 0; i < n; i++) {
        printf("%d %d\n", i, d[i]);
    }

    return 0;
}