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
	heap.Init(&pq)

	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 <stdio.h>
#include <vector>

#define inf 500000
using namespace std;

int main() {
    int n, tmp, tmp2, kazu;
    cin >> n;
    vector<vector<int> > g(n);//与えられるグラフ

    //初期化
    vector <int> d(n,inf);
    for (int i = 1; i < n; ++i) {
        d[i] = inf;
    }

    //入力を受け取る
    for (int i = 0; i < n; ++i) {
        cin >> kazu;
        cin >> kazu;
        g[i].push_back(i);
        g[i].push_back(0);
        for (int j = 0; j < kazu; ++j) {
            cin >> tmp >> tmp2;
            g[tmp].push_back(i);
            g[tmp].push_back(tmp2);
        }
    }
/*
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < g[i].size(); ++j) {
            cout << g[i][j] << " ";
        }
        cout << endl;
    }
    */
    d[0]=0;
    bool flag = true;
    while(flag){
        flag = false;
        for (int i = 0; i < n; ++i) { // i 今最短経路を求めているノード
/*
            for (int l = 0; l < n; ++l) {
                cout << d[i] << " ";
            }
            cout << endl;
*/
            for (int j = 0; j < g[i].size()/2; ++j) { // i j の組でその２点間の重み
                //cout << i << " " << j << " " << d[i] << " " << d[j*2] << " " << g[i][i*2+1] << endl;
                if (d[i] > d[g[i][j*2]] + g[i][j*2+1]) {
                    d[i] = d[g[i][j*2]] + g[i][j*2+1];
                    flag = true;

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


    return 0;
}

C++: #include<iostream>
using namespace std;
#include<queue>
#include<vector>
#include<string>
#include<string.h>
#include<algorithm>
bool b[2003];

#define REP(i, a) for(int i=0;i<a;i++)

int main()
{
	int min,b,a,k,m[101][101],n ,e,p[101],d[101],u,v; //u ?????????v????????¨
	bool color[101];
	cin>>n;
	REP(i, n) {
		REP(j, n) {
		m[i][j]=2001;
		}
	}
	REP(i, n) {
		cin>>u>>k;
		REP(i, k) {
			cin>>a>>b;
			m[u][a]=b;
			if(m[u][a]==-1) m[u][a]=2001;
		}
		color[i]=0;
		d[i]=2001;
	}
	a=0;
	d[0]=0;
	while(1){
		min=2001;
		u=-1;
		REP(i,n){
			if(min>d[i]&&color[i]==0){
				min=d[i];
				u=i;
			}
		}
		if(u==-1) break;
		color[u]=1;
		REP(i,n){
			if(color[i]==0&&m[u][i]!=2001){
				if(d[i]>m[u][i]+d[u]){
					d[i]=m[u][i]+d[u];
				}
			}
		}

	}
	min=0;
	REP(i,n){
		cout<<i<<" "<<(d[i] == 2001 ? -1 : d[i])<<endl;
	
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
int main()
{
    int n, inf = 100000000;
    scanf("%d", &n);
    vector<vector<pair<int, int>>> a(n, vector<pair<int, int>>(0));
    for (int i = 0, u, k; i < n; i++)
    {
        scanf("%d %d", &u, &k);
        for (int j = 0, v, c; j < k; j++)
        {
            scanf("%d %d", &v, &c);
            a[i].push_back(make_pair(c, v));
        }
    }
    
    vector<int> cost(n, inf), vis(n, 0);
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>> > q;
    cost[0] = 0;
    q.push(make_pair(0, 0));
    for (pair<int, int> t; !q.empty(); )
    {
        
        t = q.top();
        q.pop();
        vis[t.second] = true;
        if (cost[t.second] < t.first)
        {
            continue;
        }
        for (int i = 0; i < a[t.second].size(); i++)
        {
            pair<int, int> j = a[t.second][i];
            if (!vis[j.second] && cost[j.second] > cost[t.second] + j.first)
            {
                cost[j.second] = cost[t.second] + j.first;
                q.push(make_pair(cost[j.second], j.second));
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        printf("%d %d\n", i, cost[i]);
    }
}

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]);
	}
}