Go: package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	"container/heap"
)

type Node struct {
	Id int
	Dis int
}

type PriorityQueue []*Node

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dis < pq[j].Dis
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(*Node))
}

func (pq *PriorityQueue) Pop() interface{} {
	n := len(*pq)
	pop := (*pq)[n-1]
	*pq = (*pq)[0:n-1]
	return pop
}

func main() {
	var n int
	fmt.Scan(&n)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			sc.Scan()
			g[u][j], _ = strconv.Atoi(sc.Text())
			sc.Scan()
			c[u][j], _ = strconv.Atoi(sc.Text())
		}

		if u == 0 {
			d[u] = 0
		} else {
			d[u] = 1 << 30
		}
		pq.Push(&Node{u, d[u]})
	}
	heap.Init(&pq)

	for pq.Len() > 0 {
		node := heap.Pop(&pq).(*Node)
		for i := 0; i < len(g[node.Id]); i++ {
			nextId := g[node.Id][i]
			nextDis := node.Dis + c[node.Id][i]
			if nextDis < d[nextId] {
				d[nextId] = nextDis
				heap.Push(&pq, &Node{nextId, nextDis})
			}
		}
	}

	wr := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		wr.WriteString(strconv.Itoa(i))
		wr.WriteString(" ")
		wr.WriteString(strconv.Itoa(d[i]))
		wr.WriteString("\n")
	}
	wr.Flush()
}

C++: #include<iostream>
#include<climits>
using namespace std;

typedef struct{
  int A[10010];
  int ans;
}node;
node T[10010];
int Q[10000003];
int head=0;
int tail=1;
int n;

void function(int num){
  while(true){
    if(head==tail)break;
    num=Q[head++];
        if(head==9999999)head=1;
    for(int i=0;i<n;i++){
      if(T[num].A[i]!=-1){
	if(T[i].ans>T[num].ans+T[num].A[i]){
	  T[i].ans=T[num].ans+T[num].A[i];
	  Q[tail++]=i;
	  	  if(tail==9999999)tail=1;
	}
      }
    }
  }
}

int main(){
  int num,son,z,w;
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      T[i].A[j]=-1;
    }
  }


  for(int i=0;i<n;i++){
    cin>>num>>son;
    T[num].ans=INT_MAX;
    for(int j=0;j<son;j++){
      cin>>z>>w;
      T[num].A[z]=w;
      }
  }
  Q[0]=0;
  T[0].ans=0;
  function(0);
 
  for(int i=0;i<n;i++){
      cout<<i<<" "<<T[i].ans<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;
int n;
int res = 0;
struct node {
    int id;
    int dist;
    bool searched;
};

node v[10000];
int edge[10000][10000];

int main() {
    cin >> n;
    REP(i, n) {
        int u, k;
        cin >> u >> k;
        v[u].id = u;
        v[u].dist = INF;
        v[u].searched = false;
        REP(j, n) edge[i][j] = INF;
        REP(j, k){
            int to, cost;
            cin >> to >> cost;
            edge[i][to] = cost;
        }
    }
    v[0].dist = 0;
    int prev = 0;
    REP(i, n){
        int minimum = INF;
        REP(j, n){
            if(!v[j].searched && minimum >= v[j].dist){
                prev = j;
                minimum = v[j].dist;
            }
        }
        REP(j, n){
            if(!v[j].searched && edge[prev][j] != INF){
                v[j].dist = min(v[j].dist, v[prev].dist + edge[prev][j]);
            }
        }
        v[prev].searched = true;
    }
    REP(i, n) cout << i << " " << v[i].dist << endl;
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<cstring>
#define P pair<int,int>//cost to
using namespace std;

vector<P>rinsetu[10000];
int mincost[10000];
signed main() {
	int a; cin >> a;
	for (int b = 0; b < a; b++) {
		int c, d; cin >> c >> d;
		for (int e = 0; e < d; e++) {
			int f, g; scanf("%d%d", &f, &g);
			rinsetu[c].push_back(P(g,f));
		}
	}
	fill(mincost, mincost + a, 1 << 29);
	mincost[0] = 0;
	priority_queue<P, vector<P>, greater<P>>Q;
	Q.push(P(0,0));
	while (Q.size()) {
		P t = Q.top(); Q.pop();
		if (t.first > mincost[t.second])continue;
		for (P i : rinsetu[t.second]) {
			if (mincost[i.second] > t.first + i.first) {
				mincost[i.second] = t.first + i.first;
				Q.push(P(t.first + i.first,i.second));
			}
		}
	}
	for (int i = 0; i < a; i++) {
		cout << i << " " << mincost[i] << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;
static const int MAX=10000;
static const int INFTY = (1<<21);

vector< pair<int,int> >M[MAX]; //?????\??¨
priority_queue< pair<int,int> > PQ; //????????§??????, first???d[i], second???i??? ?????¨??¶?????????first???????????°
bool visited[MAX]; //???????¢??????????
int d[MAX]; //?????????????????¬

void dijkstra_implementsPQ(int n)
{
    //init
    for(int i=0;i<n;i++)
    {
        d[i]=INFTY;
        visited[i]=false;
    }
    //select node 0
    d[0]=0;
    PQ.push(make_pair(0,0));

    while(!PQ.empty())
    {
        //currently the top of PQ is the shortest one
        pair<int,int> temp=PQ.top();PQ.pop();
        int u=temp.second;

        visited[u]=true;
        if(d[u]<temp.first*(-1)) continue;

        //update
        for(int j=0;j<M[u].size();j++)
        {
            int v=M[u][j].first;
            if(visited[v]==true) continue;
            //else try updating
            if(d[v]>d[u]+M[u][j].second)
            {
                d[v]=d[u]+M[u][j].second;
                PQ.push(make_pair(d[v]*(-1),v));
            }
        }
    }
    //print
    for(int i=0;i<n;i++)  cout<<i<<' '<<(d[i]==INFTY?-1:d[i])<<endl;

}
int main()
{
    int n;
    cin>>n;

    for(int i=0;i<n;i++)
    {
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;j++)
        {
            int v,d;
            cin>>v>>d;
            M[u].push_back(make_pair(v,d));
        }
    }

    dijkstra_implementsPQ(n);
}

C++: #include <cstdint>
#include <queue>
#include <vector>

using namespace std;

#define GRAPH_SIZE 10000
#define WEIGHT_MAX UINT32_MAX

enum state_t { WHITE, GRAY, BLACK };

static state_t state[GRAPH_SIZE];
static priority_queue<pair<uint32_t, uint32_t>, vector<pair<uint32_t, uint32_t>>, greater<pair<uint32_t, uint32_t>>> min_queue;
static vector<pair<uint32_t, uint32_t>> graph[GRAPH_SIZE];
static uint32_t dist[GRAPH_SIZE];

void single_source_shortest_path(size_t num)
{
  for (uint32_t i = 0; i < num; i++) {
    // dist[i] = WEIGHT_MAX;
    state[i] = WHITE;
  }

  state[0] = GRAY;
  min_queue.push(make_pair(0, 0));

  while (!min_queue.empty()) {
    pair<uint32_t, uint32_t> vertex = min_queue.top();
    min_queue.pop();
    if (state[vertex.first] != BLACK) {
      state[vertex.first] = BLACK;
      dist[vertex.first] = vertex.first;

      for (uint32_t i = 0; i < graph[vertex.first].size(); i++) {
        pair<uint32_t, uint32_t> to = graph[vertex.first][i];
        if (state[vertex.first] != BLACK) {
          min_queue.push(make_pair(vertex.first, vertex.second + to.second));
          state[vertex.first] = GRAY;
        }
      }
    }
  }
}

#include <iostream>

int32_t main()
{
  uint32_t num;
  cin >> num;

  for (uint32_t i = 0; i < num; i++) {
    uint32_t index, len;
    cin >> index >> len;
    for (uint32_t j = 0; j < len; j++) {
      uint32_t connect, weight;
      graph[index].push_back(make_pair(connect, weight));
    }
  }

  single_source_shortest_path(num);

  for (uint32_t i = 0; i < num; i++) {
    cout << i << " " << dist[i] << endl;
  }

  return 0;
}