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 <vector>
#include <queue>
#include <algorithm>
#include <climits>


#define MAX 10000


using namespace std;
typedef pair<int, int> pi;

vector< pi > hdrs[MAX];
priority_queue< pi, vector<pi>, greater<pi> > distances;
bool is_tree[MAX];
int d[MAX];
int n;

void dijkstra()
{
    for (int i = 0; i < n; i++) {
        is_tree[i] = false;
        d[i] = INT_MAX;
    }

    distances.push(make_pair(0, 0));
    d[0] = 0;
    while (!distances.empty()) {
        // min_distance, vertex_id
        pi now = distances.top();
        distances.pop();

        if (d[now.second] < now.first)
            continue;
        is_tree[now.second] = true;

        for (vector<pi>::iterator it = hdrs[now.second].begin(); it != hdrs[now.second].end(); it++) {
            // *(it).second is same as it->second
            if (!is_tree[(*it).second] && now.first + (*it).first < d[(*it).second]) {
                d[(*it).second] = now.first + (*it).first;
                distances.push(make_pair(d[(*it).second], (*it).second));
            }
        }
    }
}


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;
            // cost, vertex_id
            hdrs[u].push_back(make_pair(c, v));
        }
    }

    dijkstra();

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

    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <climits>
#include <queue>
#include <map>
using namespace std;

typedef map<int, int>::iterator mitr;

map<int, int> w[10000];
int d[10000];
char pos[10000];

priority_queue<pair<int,int> > others;
pair<int,int> p;

void findPath(){
    p = others.top();
    others.pop();
    while(pos[p.second]){
        p = others.top();
        others.pop();
    }
    pos[p.second]=1;

    int tmpu = p.second;
    int tmpd = -p.first;

    for(mitr i=w[tmpu].begin();i!=w[tmpu].end();i++){
        if(tmpd + i->second < d[i->first]){
            d[i->first] = tmpd + i->second;
            others.push(make_pair(-d[i->first],i->first));
        }
    }
}

int main(){
    int i,j,u,k,n,v,c;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d %d",&v,&c);
            w[u][v] = c;
        }
    }

    memset(pos,0,sizeof(char)*100);
    for(i=0;i<n;i++)d[i]=INT_MAX;
    d[0] = 0;
    others.push(make_pair(0,0));
    for(i=0;i<n;i++)findPath();
    for(i=0;i<n;i++)printf("%d %d\n",i,d[i]);

    return 0;
}

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

int n;
const int INF = 1000000;
vector<vector<int> > v, c;
vector<int> w;

void trip(int id, int dp) {
	if (dp > n)
		return;

	for (int j = 0; j < (int)v[id].size(); j++) {
		if (w[v[id][j]] > w[id] + c[id][j]) {
			w[v[id][j]] = w[id] + c[id][j];
			trip(v[id][j], dp + 1);
		}
	}
}

int main()
{
	cin >> n;

	int u, k, v1, c1;
	v.resize(n);
	c.resize(n);
	w.assign(n, INF);

	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v1 >> c1;
			v[u].push_back(v1);
			c[u].push_back(c1);
		}
	}

	w[0] = 0;
	trip(0, 1);

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

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<climits>
using namespace std;
  
#define N 10001
int n;
  
int g[N][N];
  
int weight[N];
bool us[N];
  
//prim
void prim(){
  
  int v;
   
  weight[0]=0;
    
  while(true){
    v=-1;
     
    for(int i=0;i<n;i++){
      if(us[i]!=true && (v==-1 ||weight[i]<weight[v]))v=i;
    }
  
    if(v==-1)break;
    us[v]=true;
   
  
    for(int i=0;i<n;i++){
      if(weight[i]>(g[v][i]+weight[v])){
  
        weight[i]=(g[v][i]+weight[v]);
        //      cout <<"fsafa"<<endl;
      }
    }
  }
   
}
  
  
int main(){
  
  int u,k1,c,v;
  
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      g[i][j]=9953535;
    }
  }
  
  //load n
  cin >>n;
  
  //load data
  for(int i=0;i<n;i++){
    weight[i]=INT_MAX;
    us[i]=false;
    scanf("%d %d",&u,&k1);
    for(int j=0;j<k1;j++){
      scanf("%d %d",&v,&c);
      g[u][v]=c;
      //    cout <<g[i][j]<<" ";
    }
    //    cout <<endl;
  }
  
  
  
  
  //print
  prim();
  
  for(int i=0;i<n;i++){
    cout <<i<<" "<<weight[i]<<endl;
  }
delete g[];
  return 0;
  
}

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

const int MAX = 10000;
const int INF = 1e9 + 7;

int n;
vector<pair<int, int> > adj[MAX];

void dijkstra()
{
  int d[MAX], color[MAX];
  priority_queue<pair<int, int> > pq;

  fill(d, d + MAX, INF);
  fill(color, color + MAX, 0);

  d[0] = 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;
  }
}

signed main()
{
  int u, k, c, v;

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

  dijkstra();

  return (0);
}