Go: package main

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

const NIL = -1

type Node struct {
	id     int
	weight int
}

func init() {
	sc.Split(bufio.ScanWords)
}

type NodeHeap []Node

func (h NodeHeap) Len() int           { return len(h) }
func (h NodeHeap) Less(i, j int) bool { return h[i].weight < h[j].weight }
func (h NodeHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *NodeHeap) Push(x interface{}) {
	*h = append(*h, x.(Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()

	route := make([][]Node, n)
	weight := make([]int, n)
	for i := 0; i < n; i++ {
		weight[i] = NIL
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		route[i] = make([]Node, k)
		for j := 0; j < k; j++ {
			route[u][j] = Node{id: scanInt(), weight: scanInt()}
		}
	}

	start := Node{id: 0, weight: 0}
	h := &NodeHeap{start}
	heap.Init(h)

	for h.Len() > 0 {
		node := heap.Pop(h).(Node)
		if weight[node.id] != NIL {
			continue
		}
		weight[node.id] = node.weight

		for _, nextNode := range route[node.id] {
			if weight[nextNode.id] != NIL {
				continue
			}
			nextNode.weight += node.weight
			heap.Push(h, nextNode)
		}
	}

	for i, w := range weight {
		fmt.Println(i, w)
	}
}

C++: #include <cassert>
#include <climits>
#include <algorithm>
#include <iostream>
#include <vector>
#include <list>
#include <string>


class TVertex;
struct TPath
{
    int Cost;
    TVertex* Target;
    TPath(TVertex* ATarget, int ACost)
     : Target(ATarget), Cost(ACost) {}
};
class TVertex
{
    int FIndex;
    std::list<TPath> FList;
    int FDistance;

public:
    TVertex(int Index)
     : FIndex(Index), FDistance(INT_MAX)
    {}
    void AddPath(const TPath& Path)
    {
        FList.push_back(Path);
    }
    void PrintDistance(std::ostream& out)const
    {
        out << FIndex << " " << FDistance << std::endl;
    }
    void BreadthFirstSearch(int Distance)
    {
        if(FDistance <= Distance) return;
        FDistance = Distance;
        for(std::list<TPath>::iterator It = FList.begin(); It != FList.end(); ++It){
            It->Target->BreadthFirstSearch(Distance + It->Cost);
        }
    }
};
class TGraph
{
    std::vector<TVertex*> FTable;
    void Init(int n)
    {
        assert(n > 0);
        FTable.resize(n);
        for(int i = 0; i < n; ++i){
            FTable[i] = new TVertex(i);
        }
    }
public:
    TGraph(int n)
    {
        Init(n);
    }
    
    void SetupVertex(std::istream& in)
    {
        int Index;
        in >> Index;
        assert(Index >= 0);
        assert(Index < FTable.size());
        int k;
        in >> k;
        for(int i = 0; i < k; ++i){
            int v, c;
            in >> v >> c;
            FTable[Index]->AddPath(TPath(FTable[v], c));
        }
    }
    void BreadthFirstSearch()
    {
        FTable[0]->BreadthFirstSearch(0);
    }
    void PrintDistance(std::ostream& out)
    {
        for(int i = 0; i < FTable.size(); ++i){
            FTable[i]->PrintDistance(out);
        }
    }
};

int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int n;
    std::cin >> n;
    TGraph Graph(n);
    for(int i = 0; i < n; ++i){
        Graph.SetupVertex(std::cin);
    }
    Graph.BreadthFirstSearch();
    Graph.PrintDistance(std::cout);
    return 0;
    
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

const long long INFF = 1e18;

const int MAX_N = 11000;
using TYPE = long long; // ?????¢???????????\??????
vector<pair<int, TYPE> > G[MAX_N];

vector<TYPE> A_star(int start){
	vector<TYPE> dist(MAX_N, INFF);
	dist[start] = 0;//dist[i] :=???start->i?????§??????????????¢
	priority_queue<pair<TYPE, int>, vector<pair<TYPE, int> >, greater<pair<TYPE, int> > >  que;
	que.push(make_pair(1, start));
	while(!que.empty()){
		TYPE cost; int u;//????????§???????????£????????? ?????¨?????????
		cost = que.top().first, u = que.top().second;
		que.pop();
		// if(dist[u] < cost) continue;
		for (auto tmp : G[u]){
			int v = tmp.first; TYPE time = tmp.second;//??£??\???????????? ?????????????????§????????????
			if(dist[v] > dist[u] + time){//u->v
				dist[v] = dist[u] + time;
				TYPE h = 1; // ??´???????????§?????¨??????
				// printf("%f\n", h);
				que.push(make_pair(dist[v] + h, v));
			}
		}
	}
	return dist;
}

int main(void) {
	int n; cin >> n;
	rep(q, n) {
		int u, k; cin >> u >> k;
		vector<int> v(k); vector<long long> c(k);
		rep(i, k) cin >> v[i] >> c[i];
		rep(i, k) G[u].push_back(make_pair(v[i], c[i]));
	}
	auto dist = dijkstra(0);
	rep(i, n) printf("%d %d\n", i, dist[i]);
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
const int maxn=10000+10;
const int INF=1<<21;
typedef pair<int,int> P;
typedef struct{int to,cost;}Edge;
vector<Edge> g[maxn];
int d[maxn];
int n;
void dj(int s)
{
    fill(d,d+n,INF);
    d[s]=0;
    priority_queue<P,vector<P>,greater<P> > que;
    que.push(P(0,s));
    while(!que.empty())
    {
        P p=que.top();que.pop();
        int u=p.second;
        if(p.first>d[u]) continue;
        for(int i=0;i<g[u].size();i++)
        {
            Edge &e=g[u][i];
            if(d[e.to]>d[u]+e.cost)
            {
                d[e.to]=d[u]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        printf("%d %d\n",i,d[i]);
    }
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    int id,c;
    for(int i=0; i<n; i++)
    {
        scanf("%d%d",&id,&c);
        while(c--)
        {
            Edge e;
            scanf("%d%d",&e.to,&e.cost);
            g[id].push_back(e);
        }
    }
    dj(0);

    return 0;
}

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

struct Edge {
  /*
    dst -> destination
    weight -> weight
   */
  int dst,weight;
};

struct Data {

  int place,min;

  bool operator < (const Data& data)const{
    //if( min < data.min ) => true;
    if(data.min != min)return min > data.min;
    return data.place > place;
  }

};

//int cost[100001][100001];
vector<Edge> cost[10001];
int n;
int mindist[10001];
bool used[10001];

void dijkstra(){

  for(int i=0 ; i < 10001 ; i++){
    mindist[i]=1e9;
  }
  
  mindist[0]=0;

  priority_queue<Data> PQ;

  PQ.push((Data){0,0});

  while(!PQ.empty()){
    Data a=PQ.top();
    PQ.pop();
    if( mindist[a.place] < a.min ) continue;
    for(int i=0 ; i < (int)cost[a.place].size() ; i++){
      if(mindist[cost[a.place][i].dst] > cost[a.place][i].weight+mindist[a.place]){
	mindist[cost[a.place][i].dst] = cost[a.place][i].weight+mindist[a.place];
	PQ.push((Data){cost[a.place][i].dst,mindist[cost[a.place][i].dst]});
      }
      //cost[a.place].pop_back();
    } 
  }
  
  for(int i=0 ; i < n ; i++){
    cout <<i<<" "<<mindist[i]<<endl;
  }
  
}
int main(){
  
  int u,k,v,c;
  
  // 0 -> 1 weight : 3
  /*  
      cost[0].push_back((Edge){1,3});
      cost[0].push_back((Edge){0,4});
      cost[2].push_back((Edge){0,3});
  */
  
  cin >>n;
  
  for(int i=0 ; i < n ; i++){
    cin >>u>>k;
    for(int j=0 ; j < k ; j++){
      cin >>v>>c;
      cost[u].push_back((Edge){v,c});
    }
  }

  dijkstra();

  return 0;
}


/*
1sec => 10^8


 */