Go: package main

import (
	"fmt"
	"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)

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
			fmt.Scan(&c[u][j])
		}

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

	for i := 0; i < n; i++ {
		fmt.Println(i, d[i])
	}
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define INF 200001 
using namespace std;
int n;
int A[1000][1000];
int D[1000][1000];
 
void Init(int f){
  for(int i=0;i<f;i++){
    for(int j=0;j<f;j++)D[i][j] = INF;
  } 
}
 
int main(){
  scanf("%d",&n);
  int u,k,C,V;
  Init(n);
  
  for(int i=0;i<n;i++){
      scanf("%d %d",&u,&k);    
      for(int j=0;j<k;j++){
    scanf("%d %d",&V,&C);
    D[u][V] = C;
    D[V][u] = C;
      }    
  }
   
  for(int i=0;i<n;i++)D[i][i] = 0;
  for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j] = D[j][i] = min(D[i][j],D[i][k] + D[k][j]);

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

C++: //#include "stdc++.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <queue>
//#include "my_gettime.hpp"
//#include "my_random.hpp"
//#include "my_util.hpp"
//using namespace std;

struct Edge{
	Edge(int f, int s, int w){first = f; second = s; weight = w;};
	int first;
	int second;
	int weight;
};

struct NodeP{
	NodeP(){};
	NodeP(int i, int p, int w){id = i; prev = p; weight = w;}
	int id;
	int prev;
	int weight;
	bool operator<(const NodeP & inRhs) const{ return weight < inRhs.weight; }
	bool operator>(const NodeP & inRhs) const{ return weight > inRhs.weight; }
};

#define INF (1<<30)
class Graph{
public:
	Graph(int numnodes);
	//~Graph();
	void addEdge(Edge a);
	void addEdge_nonDirect(Edge e);
	std::vector<NodeP> dijkstra(int start);
	int numNodes;
	//Edge *adj;
	std::vector < std::vector<Edge> > adj;
};
Graph::Graph(int n){
	numNodes = n;
	//adj = (Edge *)malloc(sizeof(Edge)*n*n);
	adj.resize(n);
}
void Graph::addEdge(Edge e){
	//adj[ e.first * numNodes + e.second ] = e;
	adj[e.first].push_back(e);
}
void Graph::addEdge_nonDirect(Edge e){
	adj[e.first].push_back(e);
	Edge e2 = e;
	e2.first = e.second;
	e2.second = e.first;
	adj[e2.first].push_back(e2);
}
std::vector<NodeP> Graph::dijkstra(int start){
	//using P = pair<int , int>;
	int *cost = (int *)malloc(sizeof(int)*numNodes);
	char *flag = (char *)malloc(sizeof(char)*numNodes);
	for(int i=0;i<numNodes;i++) flag[i] = 0;
	for(int i=0;i<numNodes;i++) cost[i] = INF;
	cost[start]=0;
	std::priority_queue < NodeP ,std::vector<NodeP>, std::greater<NodeP> > Q;
	Q.push(NodeP(start,0, 0));
	std::vector <NodeP> nodeps(numNodes);

	while( !Q.empty() ){
		NodeP node = Q.top();
		Q.pop();
		if( flag[node.id] == 1 ) continue;
		flag[node.id] = 1;
		cost[node.id] = node.weight;

		nodeps[node.id] = node;

		typedef std::vector<Edge>::iterator ITR;
		for( ITR itr = adj[node.id].begin(); itr !=adj[node.id].end(); itr++ ){
			int dis = node.weight + itr->weight;
			if( cost[itr->second] > dis ){
				Q.push(NodeP(itr->second, node.id, dis));
			}
		}

	}

	free(cost);
	free(flag);

	return nodeps;
}

int main(int argc ,char **argv){
	using namespace std;

	int numNodes;
	cin >> numNodes;

	Graph g(numNodes);

	for(int i=0;i<numNodes;i++){
		int nodeid, numedge;
		cin >> nodeid >> numedge;
		for(int j=0;j<numedge;j++){
			int target, weight;
			cin >> target >> weight;
		//	cout<< nodeid<<" "<<target<<" "<<weight<<endl;
			g.addEdge(Edge(nodeid,target,weight));
		}
	}
	vector<NodeP> nodeps = g.dijkstra(0);
	typedef std::vector<NodeP>::iterator ITR;
	for( ITR itr = nodeps.begin(); itr !=nodeps.end(); itr++ ){
		printf("%d %d\n",itr->prev,itr->id/*,itr->weight*/);
	}
	return 0;
}

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

using namespace std;

#define llong long long 
typedef struct data{
	vector<int> way;
	vector<int> waycost;
	int useway;
	int cost;
}data;

data d[101];
bool ok[101];
int sum;
int hownum;

void solve(int N, int before){
	for(int i = 0; i < d[N].way.size(); i++){
		if(d[N].cost + d[N].waycost[i] < d[d[N].way[i] ].cost){
			d[d[N].way[i] ].cost = min(d[d[N].way[i]].cost, d[N].cost + d[N].waycost[i]);
			d[d[N].way[i]].useway = N;
		}
	}
}

int main(){
	fill_n(ok, 101, false);
	int howway;
	int num;
	cin >> hownum;
	for(int i = 0; i < hownum; i++){
		cin >> num;
		cin >> howway;
		for(int j = 0; j < howway; j++){
			int w,c;
			cin >> w >> c;
			d[num].way.push_back(w);
			d[num].waycost.push_back(c);
		}

		if(num == 0) d[num].cost = 0;
		else d[num].cost = 10000000;
	}

	for(int j = 0; j < hownum; j++){
		for(int i = 0; i < hownum; i++){
			solve(i, -1);
		}
	}

	for(int i = 0; i < hownum; i++){
		cout << i << " " << d[i].cost << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

const int SIZE = 101;
const int INF = 1 << 21;
int d[SIZE], p[SIZE], state[SIZE];

void dijkstra(int s, int n, int **a) {
  rep(i, n) {
    d[i] = INF;
    p[i] = -1;
  }
  d[s] = 0;

  while (1) {
    int u = -1, minv = INF;
    rep(i, n) {
      if (d[i] < minv && state[i] != 1) {
        u = i;
        minv = d[i];
      }
    }

    if (u == -1) break;

    state[u] = 1;

    rep(i, n) {
      if (a[u][i] != INF) {
        int v = i, w = a[u][i];
        if (state[v] == 1) continue;
        if (d[v] > d[u] + w) { d[v] = d[u] + w; }
      }
    }
  }
}

int main() {
  int n;
  std::cin >> n;
  int **a = new int *[n];
  rep(i, n) a[i] = new int[n];

  rep(i, n) rep(j, n) a[i][j] = INF;

  rep(i, n) {
    int u, k, v, c;
    std::cin >> u >> k;
    rep(j, k) {
      std::cin >> v >> c;
      a[u][v] = c;
    }
  }

  dijkstra(0, n, a);
  rep(i, n) { std::cout << i << ' ' << d[i] << '\n'; }

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define inf 1e9+100

int n, u, k, v, c, d[100];
vector<pair<int,int> > e[100];

void dijkstra(int n, vector<pair<int,int> > e[], int *d, int s) {
	priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > que;
	fill(d, d+n, inf), d[s] = 0;
	que.push({0,s});
	while(!que.empty()) {
		int v = que.top().second, dis = que.top().first; que.pop();
		if (d[v]<dis) continue;
		for (int i = 0; i < e[v].size(); ++i) {
			int to = e[v][i].first, cost = e[v][i].second;
			if (d[to] > d[v] + cost) {
				d[to] = d[v] + cost;
				que.push({d[to], to});
			}
		}
	}
}

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> u >> k;
		for (int j = 0; j < k; ++j) {
			cin >> v >> c;
			e[u].push_back({v, c});
		}
	}
	dijkstra(n,e,d,0);
	for (int i = 0; i < n; ++i) cout << i << ' ' << d[i] << endl;
}