Go: package main

import (
	"strconv"
	"fmt"
	"bufio"
	"os"
)
const INF = 1 << 21
var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}


func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	adj := make([][]int, n)
	for i := range adj {
		adj[i] = make([]int, n)
	}

	for i := 0;i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			v := nextInt()
			c := nextInt()
			adj[u][v] = c
		}
	}

	// for i := range adj {
	// 	fmt.Println(adj[i])
	// }

	dist := make([]int, n)
	prev := make([]int, n)
	visited := make([]bool, n)
	dijkstra := func(start int, size int) {
		for i := 0; i < size; i++ {
			dist[i] = INF
			prev[i] = -1
			visited[i] = false
		}
		dist[start] = 0
		for {
			u := -1
			tmp_min := INF
			for i := 0; i < size; i++ {
				if visited[i] == false && dist[i] < tmp_min {
					tmp_min = dist[i]
					u = i
				}
			}
			if u == -1 {
				break
			}
			visited[u] = true
			for i := 0; i < size; i++ {
				if adj[u][i] > 0 {
					w := adj[u][i]
					newlen := dist[u] + w
					if newlen < dist[i] {
						dist[i] = newlen
						prev[i] = u
					}
				}
			}
		}
	}
	dijkstra(0, n)
	for i, cost := range dist {
		fmt.Printf("%d %d\n", i, cost)
	}
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <string.h>

using namespace std;
static const int INF = 1e9;
typedef pair<int, int> P;
struct edge
{
	int to;
	int cost;
};

int d[101];
vector<edge> G[101];

void solve()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; ++j)
		{
			int to, cost;
			cin >> to >> cost;
			edge e1;
			e1.to = to;
			e1.cost = cost;
			G[u].push_back(e1);
		}
	}
	for (int i = 0; i < 101; ++i)
	{
		d[i] = INF;
	}
	d[0] = 0;
	priority_queue<P, vector<P>, greater<P> > pque;
	pque.push(P(0, 0));
	while (!pque.empty())
	{
		P p = pque.top();
		pque.pop();
		int v = p.second;
		for (int i = 0; i < G[v].size(); ++i)
		{
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				pque.push(P(d[e.to], e.to));
			}
		}
	}
	for (int i = 0; i < n; ++i)
	{
		cout << i << " " << d[i] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<iostream>
using namespace std;
static const int MAX=100;
static const int INF=(1<<21);
static const int WH=0;
static const int GRY=1;
static const int BL=2;

int n, MA[MAX][MAX];

void DijkStra(){
  int minV;
  int d[MAX], color[MAX];

  for(int i=0; i<n; i++)
  {
    d[i]=INF;
    color[i]=WH;
  }

  d[0]=0;
  color[0]=GRY;

  while(1)
  {
    minV=INF;
    int u = -1;
    for(int i=0; i<n; i++)
    {
      if(minV > d[i] && color[i] != BL)
      {
        u=i;
        minV=d[i];
      }
    }
    if(u == -1) break;
    color[u]=BL;
    for(int v=0; v<n; v++)
    {
      if(color[v] != BL && MA[u][v] != INF)
      {
        if(d[v] > d[u] + MA[u][v])
        {
          d[v]=d[u]+MA[u][v];
          color[v]=GRY;
        }
      }
    }
  }

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

int main(){
  cin >> n;
  for(int i=0; i<n; i++)
  {
    for(int j=0; j<n; j++)
    {
      MA[i][j]=INF;
    }
  }

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

  DijkStra();

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n,M[105][105];
void djkstr(){
  int minv;
  int d[105],color[105];

  for(int i=0;i<n;i++){
    d[i]= 1234567890;
    color[i]=0;
  }
  d[0]=0;
  color[0]=1;
  while(1){
    minv = 1234567890;
    int u = -1;
    for(int i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=2){
	u=i;
	minv = d[i];
      }
    }
    if(u==-1)break;
    color[u]=2;
    for(int v=0;v<n;v++){
      if(color[v]!=2&&M[u][v]!=1234567890){
	if(d[v]>d[u]+M[u][v]){
	  d[v]=d[u]+M[u][v];
	  color[v]=1;
	}
      }
    }
  }
  for(int i=0;i<n;i++){
    cout << i << " " << (d[i]==1234567890?-1:d[i])<<endl;
  }
}
int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      M[i][j]=1234567890;
    }
  }
  int k,c,u,v;
  for(int i=0;i<n;i++){
    cin >> u >> k;
    for(int j=0;j<k;j++){
      cin >> v >> c;
      M[u][v]=c;
    }
  }
  djkstr();
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#define INF 1000000
using namespace std;

class vertex{
public:
  class edge{
  public:
    int to;
    int weight;
    edge(int to, int weight){
      this->to = to;
      this->weight = weight;
    }
  };

  vector<edge> edges;
  int num;
  int dis;

  vertex(){
    n++;
    vertexes.push_back(this);
  }

  bool operator< (const vertex& v) const{
    return dis < v.dis;
  }

  bool operator> (const vertex& v) const{
    return dis > v.dis;
  }

  static void dijkstra(int start){
    //距離の初期化
    for(int i=0; i<n; i++) vertexes[i]->dis=INF;
    vertexes[start]->dis=0;

    //プライオリティキューを初期化、始点を格納
    priority_queue<vertex, vector<vertex>, greater<vertex> > pq; pq.push(*vertexes[start]);


    while(!pq.empty()){
      vertex now = pq.top(); pq.pop(); //キューの先頭をポップ
      if(now.dis>vertexes[now.num]->dis) continue;
      cout << "now" << now.num << " " << now.dis << endl;

      //ポップしたキューの頂点集合について最短距離更新
      for(int i=0; i<now.edges.size(); i++){
        int newDis = now.dis+now.edges[i].weight;
        vertex* next = vertexes[now.edges[i].to];
        if(newDis < next->dis){
          next->dis = newDis;
          pq.push(*next);
        }
      }

    }


  }

  static void print(){
    for(int i=0; i<n; i++){
      cout << vertexes[i]->num << " " << vertexes[i]->dis << endl;
    }
  }
private:
  static int n;
  static vector<vertex*> vertexes;
};

int vertex::n=0;
vector<vertex*> vertex::vertexes;

int main(){
  int n; cin >> n;

  vertex graph[n];

  //入力を隣接リストのようなものに格納
  int v, k, to, weight;
  for(int i=0; i<n; i++){
    cin >> v >> k;
    graph[i].num=v;
    for(int j=0; j<k; j++){
      cin >> to >> weight;
      vertex::edge e(to, weight);
      graph[v].edges.push_back(e);
    }
  }

  vertex::dijkstra(0); //0始点のダイクストラ法

  vertex::print();

  return 0;
}

C++: #include <cstdio>
#include <vector>
#include <queue>
using namespace std;
const int MAXN = 1e4 + 7, INF = 5e5 + 7;
int d[MAXN];
struct node {
	int id, dist;
	node(int id, int dist) :id(id), dist(dist) {}
	bool operator < (const node &rhs) const {
		return dist > rhs.dist;
	}
};
vector<pair<int, int> > G[MAXN];
priority_queue<node> nodes;
int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
    	d[i] = INF;
	}
    for (int i = 0; i < n; i++) {
    	int u, k;
    	scanf("%d%d", &u, &k);
    	for (int j = 0; j < k; j++) {
    		int v, c;
    		scanf("%d%d", &v, &c);
    		G[u].push_back(make_pair(v, c));
		}
	}
	nodes.push(node(0, 0));
	while (!nodes.empty()) {
		node tmp = nodes.top();
		nodes.pop();
		if (tmp.dist > d[tmp.id]) continue;
		int cnt = G[tmp.id].size();
		for (int i = 0; i < cnt; i++) {
			if (d[G[tmp.id][i].first] > d[tmp.id] + G[tmp.id][i].second) {
				d[G[tmp.id][i].first] = d[tmp.id] + G[tmp.id][i].second;
				nodes.push(node(G[tmp.id][i].first, d[G[tmp.id][i].first]));
			}
		}
	}
	for (int i = 0; i < n; i++) {
		printf("%d %d\n", i, d[i]);
	}
	return 0;
}