Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	white int = iota
	gray
	black
)

type node struct {
	id     int
	parent int
	edge   []int
	weight []int
	color  int
}

type graph struct {
	nodes    []node
	distance []int
}

var infty = 1 << 32
var null = -1

func constructgraph() *graph {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)

	g := &graph{make([]node, n), make([]int, n)}

	for i := 0; i < n; i++ {
		id := nextInt(sc)
		edges := nextInt(sc)
		n := node{}
		n.id = id
		n.edge = make([]int, edges)
		n.weight = make([]int, edges)
		n.color = white
		for j := 0; j < edges; j++ {
			to := nextInt(sc)
			w := nextInt(sc)
			n.edge[j] = to
			n.weight[j] = w
		}
		g.nodes[id] = n
	}
	return g
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func (g *graph) preparedijkstra(s int) {
	for i := 0; i < len(g.nodes); i++ {
		g.nodes[i].color = white
		g.nodes[i].parent = null
		g.distance[i] = infty
	}
	g.distance[s] = 0
}

func (g *graph) dijkstra(s int) []int {
	g.preparedijkstra(s)

	for {
		var u int
		mincost := infty
		for i, d := range g.distance {
			if g.nodes[i].color != black && mincost > d {
				mincost = d
				u = i
			}
		}

		if mincost == infty {
			break
		}

		g.nodes[u].color = black

		for i, e := range g.nodes[u].edge {
			if g.nodes[e].color != black {
				if g.distance[e] > g.distance[u]+g.nodes[u].weight[i] {
					g.distance[e] = g.distance[u] + g.nodes[u].weight[i]
					g.nodes[e].parent = u
					g.nodes[e].color = gray
				}
			}
		}
	}
	return g.distance
}

func printShortestPath(d []int) {
	for i, v := range d {
		fmt.Printf("%d %d\n", i, v)
	}
}

func main() {
	g := constructgraph()
	d := g.dijkstra(0)
	printShortestPath(d)
}

C++: #include <bits/stdc++.h>
using namespace std;

const int INF = INT_MAX;
typedef pair<int, int> P;
typedef int long long

struct edge {int to, cost;};

/*
[input]
const vector<vector<edge>> &graph : ??\?????°??????
int s : ?§????
int g : ??????
n*/
int dijkstra(const vector<vector<edge>> &graph, int s, int g ) {
  // ????????????????±?????????????????????????
  vector<int> d(graph.size(), INF);
  // ????§?????????????????????????0????????????
  d[s] = 0;
  // ??????????????????now
  set<P> now;
  // ????§?????????????now????????\
  now.insert(P(0, s));
  
  // now????????????????????§
  while(!now.empty()) {
    // ?????¨?????????????????????pos???????´?
    int pos = now.begin()->second;
    // ?????¨??????????????????????????????????±???????????????????????????????
    if (pos == g) {
      for(int i = 0; i <= g; i++) {
        cout << i << " " << d[i] << endl;
      }
      return INF;
    }
    // now????????¢?´¢?????????????¶????
    now.erase(now.begin());
    // ?????¨??????????????¨???????????¢?´¢
    for(auto ed: graph[pos]) {
      // ??\?¶??????????????????????????????????????????¨??????????????§????????????
      // ??¨??\?¶?????????§?????¨????????????????????????????????§???????????°
      if(d[ed.to] > d[pos] + ed.cost) {
        // now????????\?¶?????????????????±????????????????????????????
        now.erase(P(d[ed.to], ed.to));
        d[ed.to] = d[pos] + ed.cost;
        now.insert(P(d[ed.to], ed.to));
      }
    }
  }
  return INF;
}
  
signed main() {
  int num;
  cin >> num;
  vector<vector<edge>> graph(num, vector<edge>());
  int f, n, k, v, c;
  for(int i = 0; i < num; i++) {
    cin >> f >> k;
	if(k == 0) continue;
    for(int j = 0; j < k; j++) {
      cin >> v >> c;
      graph[f].push_back(edge{v, c});
      graph[v].push_back(edge{f, c});
    }
  }
  dijkstra(graph, 0, num - 1);
  return 0;
}

C++: #ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var) \
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> edges(n, vector<pair<int, int>>());
  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;
      edges[i].push_back(make_pair(v, c));
    }
  }
  int count = 1;
  constexpr auto not_yet = numeric_limits<int>::max();
  vector<int> costs(n, not_yet);
  costs[0] = 0;
  auto cmp = [](const pair<int, int>& lhs, const pair<int, int>& rhs) {
    return lhs.second > rhs.second;
  };
  priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(cmp)> q(cmp);
  for (auto&& edge : edges[0]) {
    q.push(edge);
  }
  int cost = 0;
  while (true) {
    auto edge = q.top();
    q.pop();
    if (costs[edge.first] > cost + edge.second) {
      cost += edge.second;
      assert(costs[edge.first] == not_yet);
      for (auto&& e : edges[edge.first]) {
        q.push(e);
      }
      costs[edge.first] = cost;
      if (++count == n) {
        break;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << i << " " << costs[i] << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct Edge{
    ll target;
    ll weight;
};

struct State{
    ll node;
    ll sum_of_weight;

    bool operator < (const State& s)  const {
        return sum_of_weight > s.sum_of_weight;
    }
};

typedef vector<vector<Edge> > graph;

void dijkstra(graph &g, vector<ll>&d, ll start){

    priority_queue<State> pq;
    pq.push(State{start,0});

    while( pq.size() ){

        State s = pq.top(); pq.pop();

        if( d[s.node] != -1 ) continue;
        d[s.node] = s.sum_of_weight;

        for(auto edge: g[s.node]) {
            if( d[edge.target] != -1 ) continue;
            pq.push(State{edge.target, s.sum_of_weight + edge.weight});

        }
    }

}


int main(){

    ll N;
    cin >> N;

    graph G(N);
    for (int i = 0; i < N; i++)
    {
        ll u,k;
        cin >> u >> k;
        for (int j = 0; j < k; j++)
        {
            ll v,c;
            cin >> v >> c;
            G[u].push_back(Edge{v,c});
        }
    }

    vector<ll> d(N,-1);

    ll count = 1;
    dijkstra(G,d,0);

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

C++: #include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main() {
	int n, u, k, v, c, i, j, d[100][100], m[100][100], o, p[100] = { 0 }, e, q = 0;
	memset(m, 0x7f, sizeof(m));
	memset(d, 0x7f, sizeof(d));
	d[0][0] = 0;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> u >> k;
		for (j = 0; j < k; j++) {
			cin >> v >> c;
			m[u][v] = c;
		}
	}
	p[0] = 1;
	for (i = 1; i < n; i++) {
		o = d[0][n - 1];
		for (j = 0; j < n; j++) {
			d[i][j] = min(d[i][j], m[q][j] + d[i - 1][q]);
			d[i][j] = min(d[i][j], d[i - 1][j]);
			if (o >= d[i][j] && p[j] == 0) {
				e = j;
				o = d[i][j];
			}
		}
		p[e] = 1;
		q = e;
	}
	for (i = 0; i < n; i++)cout << i << ' ' << d[n - 1][i] << endl;
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
struct node{
	int v,c;
	bool operator<(const node&p)const{
		return c>p.c;
	}
};
int d[100005];
vector<node> e[100005];
bool ok[100005];
int n;
void solve(){
	priority_queue<node> q;
	ok[0]=1;
	for(int i=0;i<e[0].size();i++)q.push(e[0][i]);
	int k=1;
	while(k!=n){
		node v=q.top();q.pop();
		if(ok[v.v])continue;
		d[v.v]=v.c;
		ok[v.v]=1;
		k++;
		for(int j=0;j<e[v.v].size();j++)
			q.push({e[v.v][j].v,e[v.v][j].c+v.c});
	}
	for(int i=0;i<n;i++)
		cout<<i<<' '<<d[i]<<"\n";
}
int main(){
//	freopen("a.txt","r",stdin);
	cin.tie(0);
	int u,v,k,c;
	cin>>n;
	while(cin>>u>>k){
		for(int i=0;i<k;i++){
			cin>>v>>c;
			e[u].push_back({v,c});
		}
	}
	solve();
	return 0;
}