Go: package main

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

//make priority queue
type Item struct {
	id       int
	priority int // this state is priority and distans from start
	index    int
}

type PriorityQueue []*Item

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

// we want the ascending-priority-queue.
// So we use less than here.
func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}

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

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1 //for safety
	*pq = old[0 : n-1]
	return item
}

func (pq *PriorityQueue) update(dist int, id int) {
	for _, i := range *pq {
		if i.id == id {
			if i.priority > dist {
				i.priority = dist
			}
		}
	}
}

// the main code
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func dikstra(dist [][]int, n int) []int {
	// preparate priority queue
	inf := 1 << 30
	pq := make(PriorityQueue, n)
	shortests := make([]int, n)
	for i := 0; i < n; i++ {
		pq[i] = &Item{
			id:       i,
			priority: inf,
			index:    i,
		}

		shortests[i] = inf
	}
	pq[0].priority = 0
	shortests[0] = 0

	for pq.Len() > 0 {
		item := heap.Pop(&pq).(*Item)
		shortests[item.id] = item.priority
		for id, d := range dist[item.id] {
			if d != -1 {
				pq.update(item.priority+d, id)
			}
		}
		heap.Init(&pq)
	}
	return shortests
}

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

	// init
	n := nextInt(sc)
	dist := make([][]int, n)
	for i := 0; i < n; i++ {
		dist[i] = make([]int, n)
		for j := 0; j < n; j++ {
			dist[i][j] = -1
		}
	}

	// std Input
	for i := 0; i < n; i++ {
		u := nextInt(sc)
		k := nextInt(sc)
		for j := 0; j < k; j++ {
			v, c := nextInt(sc), nextInt(sc)
			dist[u][v] = c
		}
	}

	shortests := dikstra(dist, n)
	for i, d := range shortests {
		fmt.Printf("%d %d\n", i, d)
	}
}

C++: #include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;

int INF = 1000000001;

typedef struct edge{
  int to;
  int cost;
} edge;

int N,E;
vector< edge > G[100000];
int mincost[100000];

void dijkstra(){
  /*
  priority_queue< pair<int,int>,
                  vector< pair<int,int> > ,
                  greater< pair<int,int> > > Q;
  */
  
  //priority_queue?????£?¨?
  typedef pair<int,int> P;
  priority_queue< P , vector<P> , greater<P> > Q;

  //mincost?????????????????????????????????
  for(int i=0;i<N;i++){
    mincost[i]=INF;
  }
  mincost[0]=0; //??????????????°????????????0

  Q.push( P(0,0) );

  //????????????dijkstra ?????¬???
  while(!Q.empty()){
    int pos=Q.top().second;// position
    int pos_cost=Q.top().first;
    Q.pop();
    
    //aoj0099????????????????????§???2 ??¨??????????????§????°?????????????????????????
    if( mincost[pos] < pos_cost )continue;
    
    for(int i=0;i<(int)G[pos].size();i++){
      edge e=G[pos][i];
      if(mincost[e.to] > pos_cost+e.cost){
        mincost[e.to]=pos_cost+e.cost;
        Q.push( P( mincost[e.to] , e.to ) );
      }
    }
  }

  for(int i=0;i<N;i++){
    cout<<i<<' '<<mincost[i]<<endl;
  }
}

int main(){
  cin>>N;
  for(int i=0;i<N;i++){
    int id,k;
    cin>>id>>k;
    for(int j=0;j<k;j++){
      edge e;
      cin>>e.to>>e.cost;
      G[id].push_back(e);
    }
  }

  dijkstra();
  
  return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

void dijkstra(vector<vector<pair<int, int>>>& edges, vector<int>& ds, int start) {
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    q.push(make_pair(0, start));
    while (!q.empty()) {
        int d = q.top().first;
        int u = q.top().second;
        q.pop();
        if (ds[u] >= 0) {
            continue;
        }
        ds[u] = d;
        for (auto p : edges[u]) {
            q.push(make_pair(d + p.second, p.first));
        }
    }
}

int main() {
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> edges(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;
            edges[u].push_back(make_pair(v, c));
        }
    }

    vector<int> ds(n, -1);
    dijkstra(edges, ds, 0);

    for (int i = 0; i < n; i++) {
        cout << i << " " << ds[i] << endl;
    }
}

C++: #define ll long long
#define MAX 10000

#include "bits/stdc++.h"

using namespace std;
static const int INF = (1 << 21);

int n;
priority_queue<pair<int,int>> PQ;
vector<pair<int, int>> adj[MAX];
int color[MAX];
int d[MAX];

void dj(int s){
	for (int i = 0;i < n;i++) {
		d[i]=INF;
		color[i] = 0;
	}
	
	d[s] = 0;
	PQ.push(make_pair(0, 0));
	color[0] = 1;

	while (!PQ.empty()) {
		pair<int, int> f = PQ.top(); 
		PQ.pop();
		int u = f.second;
		color[u] = 2;

		if (d[u] < f.first*(-1)) continue;

		for(int j=0;j<adj[u].size();j++){
			int v = adj[u][j].first;
			if (color[v] == 2) continue;
			if (d[v] > d[u] + adj[u][j].second) {
				d[v] = d[u] + adj[u][j].second;
				PQ.push(make_pair(d[v] * (-1), v));
				color[v] = 1;
			}
		}
	}

	for (int i = 0;i < n;i++) {
		cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
	}

}

int main() {
	cin >> 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;
			adj[u].push_back(make_pair(v,c));
		}
	}

	dj(0);

}

C++: #include <cstdio>           // printf(), getc(), scanf()
#include <cctype>           // isdigit()
#include <vector>
#include <queue>            // priority_queue
#include <algorithm>        // fill()
#include <utility>          // pair

using namespace std;

static const int MAX_V = 10000;
static const int INF = 100000000;

typedef pair<int, int> P;
struct edge
{
	int to;
	int cost;
};

vector<edge> G[MAX_V];
int V;

void
dijkstra()
{
	priority_queue<P, vector<P>, greater<P> > que;
	int d[MAX_V];
	int u;
	unsigned int v; 

	fill(d, d + V, INF);
	d[0] = 0;
	que.push(P(0, 0));

	while (!que.empty())
	{
		P p = que.top(); que.pop();
		int u = p.second;
		if (d[u] < p.first)
			continue;

		for (v = 0; v < G[u].size(); ++v)
		{
			edge e = G[u][v];
			if (d[u] + e.cost < d[e.to])
			{
				d[e.to] = d[u] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}

	for (u = 0; u < V; ++u)
		printf("%d %d\n", u, d[u]);
}

int
main(int argc, char** argv)
{
	edge e;
	int u, v;
	int i, j, k;
	int n;
	int c;

	c = getc(stdin);
	while (c == ' ')
		c = getc(stdin);
	
	n = 0;
	while (isdigit(c))
	{
		n = n * 10 + c - '0';
		c = getc(stdin);
	}

	V = n;
	for (i = 0; i < V; ++i)
	{
		while (c == ' ' || c == '\n')
			c = getc(stdin);

		n = 0;
		while (isdigit(c))
		{
			n = n * 10 + c - '0';
			c = getc(stdin);
		}

		u = n;
		while (c == ' ')
			c = getc(stdin);

		n = 0;
		while (isdigit(c))
		{
			n = n * 10 + c - '0';
			c = getc(stdin);
		}

		k = n;
		for (j = 0; j < k; ++j)
		{
			while (c == ' ')
				c = getc(stdin);

			n = 0;
			while (isdigit(c))
			{
				n = n * 10 + c - '0';
				c = getc(stdin);
			}

			v = n;
			while (c == ' ')
				c = getc(stdin);

			n = 0;
			while (isdigit(c))
			{
				n = n * 10 + c - '0';
				c = getc(stdin);
			}

			e.to = v;
			e.cost = n;
			G[u].push_back(e);
		}
	}

	dijkstra();
	return 0;
}