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 <cassert>
#include <climits>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>


class TVertex;
struct TPath
{
    int Cost;
    TVertex* Target;
    TPath(TVertex* ATarget, int ACost)
     : Target(ATarget), Cost(ACost) {}
};
class TVertex
{
    int FIndex;
    std::vector<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::vector<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()
{
    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 reep(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) reep((i),0,(n))
typedef pair<int,int> pii;
#define F first
#define S second

int main(){
    int n;
    cin>>n;
    vector<vector<pii>> vv(n);
    rep(i,n){
        int a;
        cin>>a;
        int m;
        cin>>m;
        rep(j,m){
            int b,c;
            cin>>b>>c;
            vv[a].push_back(pii(b,c));
        }
    }
    priority_queue<pii> pq;
    pq.push(pii(0,0));
    vector<int> dp(n,-1);
    while(pq.size()){
        auto top=pq.top();
        pq.pop();
        if(dp[top.S]>=0) continue;
        dp[top.S]=-top.F;
        for(pii x:vv[top.S]){
            if(dp[x.F]>=0) continue;
            pq.push(pii(top.F-x.S,x.F));
        }
    }
    rep(i,n){
        cout<<i<<" "<<dp[i]<<endl;
    }
}

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

#define NIL -2
#define INF 1000000001

using namespace std;
static const int BLK = 2;
static const int GRY = 1;
static const int WHT = 0;

void dijkstra(const vector<vector<pair<int,int> > > &adj_list, 
                    vector<int> &color, 
                    vector<int> &parent, 
                    vector<int> &minpath,
                    int start_node)
{
    priority_queue<pair<int,int>,vector<pair<int,int> >, greater<pair<int,int> > >  PQ;
    PQ.push(make_pair(start_node,0));

    while(!PQ.empty()){
        pair<int,int> t = PQ.top(); PQ.pop();
        int u = t.second;
        color[u] = BLK;
        if(minpath[u] < t.first) continue;
        for(int i = 0;i < adj_list[u].size();i++){
            int v = adj_list[u][i].first;
            if(color[v] != BLK){
                if(minpath[u] + adj_list[u][i].second < minpath[v]){
                    minpath[v] = minpath[u] + adj_list[u][i].second;
                    parent[v] = u;
                    color[v] = GRY;
                    PQ.push(make_pair(minpath[v],v));
                }  
            }
        }
        
    }

}


int main(){
    int mat_size;
    int node, deg;
    int to,weight;
    int temp;
    int cost = 0;

    scanf("%d",&mat_size);
    vector<vector<pair<int,int> > > adj_list(mat_size);
    vector<int> color(mat_size,WHT);
    vector<int> minpath(mat_size,INF);
    vector<int> parent(mat_size,-1);
    
    for(int i = 0;i < mat_size;i++){
        scanf("%d %d",&node,&deg);
        for(int j = 0;j < deg;j++){
            scanf("%d %d", &to, &weight);
            adj_list[node].push_back(make_pair(to,weight));
        }
    }
    
    minpath[0] = 0;
    dijkstra(adj_list,color,parent,minpath,0);

    for(int i = 0; i < mat_size;i++){
        printf("%d %d\n",i,minpath[i]);
    }

    return 0;   
}

C++: #include<stdio.h>
#include<queue>
#include<string.h>
using namespace std;
#define INF 1 << 30
struct ss{
	int next;
	int to;
	int val;
}e[100050];
int head[100050];
int tot;
void add(int x,int y,int val){
	e[tot].next=head[x];
	e[tot].to=y;
	e[tot].val=val;
	head[x]=tot++;
}
int n;
int vis[100050]={0};
int dis[10005];
void spfa(){
	for(int i=0;i<n;i++){
		dis[i]=INF;
	}
	vis[0]=1;
	dis[0]=0;
	queue<int> st;
	st.push(0);
	while(!st.empty()){
		int t=st.front();
		st.pop();
		vis[t]=0;
		for(int i=head[t];i!=-1;i=e[i].next){
			int to=e[i].to;
			if(dis[to]>dis[t]+e[i].val){
				dis[to]=dis[t]+e[i].val;
				if(!vis[to]){
					st.push(to);
					vis[to]=1;
				}
			}
		}
	}
}
int main(){
	scanf("%d",&n);
	tot=0;
	memset(head,-1,sizeof(head));
	int a,to,val,num;
	for(int i=0;i<n;i++){
		scanf("%d %d",&a,&num);
		for(int j=1;j<=num;j++){
			scanf("%d %d",&to,&val);
			add(a,to,val);
		}
	}
	spfa();
	printf("0 0\n");
	for(int i=1;i<n;i++){
		printf("%d %d\n",i,dis[i]);
	}
	return 0;
}