Language: C++

/**
 *  単一始点最短経路：Single Source Shortest Path
 *  有向グラフ、貪欲アルゴリズム
 *  単一始点最短経路のコストを求めるプログラム
 *
 *  有向グラフ、0を始点とする単一始点最短経路を求めるダイクストラ法
 *
 *  計算量：O(n^2)
 *
 *  入力例：
 *  n：頂点数
 *  u k v1 c1 ... vk ck
 *  (※u：頂点番号)
 *  (※k：uの出次数)
 *  (※vi：uに隣接する頂点の番号)
 *  (※ci：uとviをつなぐ有向辺の重み)
 *
    5
    0 3 2 3 3 1 1 2
    1 2 0 2 3 4
    2 3 0 3 3 1 4 1
    3 4 2 1 0 1 1 4 4 3
    4 2 2 1 3 3
 *
 *
 *  出力例：
 *  各頂点の番号：v 　距離：d[v]
    0 0
    1 2
    2 2
    3 1
    4 3
 */
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

enum ColorVisit{
	WHITE,	//未訪問
	BLACK,		//確定
};

//隣接先が存在しない
static const int kInfty = 1000000;
//全頂点確定
static const int kAllDecided = -1;
static const int kNotExist = -1;
static const int kRoot = 0;

/* ex)matrix_weight
 * [0]：∞ 2 3 1 ∞
 * [1]：2 ∞ ∞ 4 ∞
 * [2]：3 ∞ ∞ 1 1
 * [3]：1 4 1 ∞ 3
 * [4]：∞ ∞ 1 3 ∞
 *
 * ex)idx_target
 *			        0 → 3 → 1 → 2 → 4
 * ex)now_min_distance
 * [0]：0  → 0 → 0 → 0 → 0 → 0
 * [1]：∞ → 2 → 2 → 2 → 2 → 2
 * [2]：∞ → 3 → 2 → 2 → 2 → 2
 * [3]：∞ → 1 → 1 → 1 → 1 → 1
 * [4]：∞ →∞ → 4 → 4 → 3 → 3
 */
//Debug
void PrintDebugNowMinDst(const  vector<int>& now_min_distance, const int apex_num){
	  for (int idx = 0; idx < apex_num; ++idx) {
		  cout << "[" << idx << "] : " << now_min_distance[idx] << endl;
	  }
}

/*確定していないかつ重み(距離)が最小のものを取り出す*/
int Setidx_target(vector<int>& now_min_distance, const vector<int>& color, const int apex_num){
  int min_distance_value = kInfty;
  int min_distance_idx = kAllDecided;
  for (int i = 0; i < apex_num; ++i) {
    if (min_distance_value <= now_min_distance[i] || color[i] == BLACK) continue;
    min_distance_idx = i;
    min_distance_value = now_min_distance[i];
  }
  return min_distance_idx;
}

void UpdateNowWeight(const vector<vector<int>>& matrix_weight,  vector<int>* now_min_distance, const vector<int>& color, const int idx_target, const int apex_num){
  for (int idx = kRoot + 1; idx < apex_num; ++idx) {
    // true：確定しているまたは、隣接先が存在しない場合 continue
    if ( color[idx] == BLACK || matrix_weight[idx_target][idx] == kNotExist ) continue;
    //説明変数
    int distance_via_idx_target = (*now_min_distance)[idx_target] + matrix_weight[idx_target][idx];
    //最短経路が短い方を採用
    if ((*now_min_distance)[idx] > distance_via_idx_target) {
    	(*now_min_distance)[idx] = distance_via_idx_target;
	  }
  }
//    PrintDebugNowMinDst((*now_min_distance), apex_num);
}

void Dijkstra(const vector<vector<int>>& matrix_weight, const int apex_num) {
  //未訪問(WHITE)、確定(BLACK)の2種類
  vector<int> color(apex_num,WHITE);
  //各頂点におけるrootまでの最短距離の初期化
  vector<int> now_min_distance(apex_num,kInfty);
  now_min_distance[0] = 0;

  while (1) {
    int idx_target = Setidx_target(now_min_distance, color, apex_num);

    //終了条件：全頂点確定した場合
    if (idx_target == kAllDecided) break;

    color[idx_target] = BLACK;

    UpdateNowWeight(matrix_weight, &now_min_distance, color, idx_target, apex_num);
  }

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

void InitMatrix(vector<vector<int>>* matrix_weight, int apex_num){
  for (int i = 0; i < apex_num; i++) {
    for (int j = 0; j < apex_num; j++) {
      (*matrix_weight)[i][j] = kNotExist;
    }
  }
}
void Creatematrix_weight(vector<vector<int>>* matrix_weight, int apex_num){
//  InitMatrix(matrix_weight, apex_num);
  for (int i = 0; i < apex_num; i++) {
	int apexData, adjNum, adjoinApex, weight;
	cin >> apexData >> adjNum;
		for (int j = 0; j < adjNum; j++) {
			cin >> adjoinApex >> weight;
			(*matrix_weight)[apexData][adjoinApex] = weight;
		}
  	 }
}


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

  vector<vector<int>> matrix_weight(apex_num,vector<int>(apex_num,kNotExist));
  Creatematrix_weight(&matrix_weight, apex_num);

  Dijkstra(matrix_weight,apex_num);

  return 0;
}
/**
 *  単一始点最短経路：Single Source Shortest Path
 *  有向グラフ、貪欲アルゴリズム
 *  単一始点最短経路のコストを求めるプログラム
 *
 *  有向グラフ、0を始点とする単一始点最短経路を求めるダイクストラ法
 *
 *  計算量：O(n^2)
 *
 *  入力例：
 *  n：頂点数
 *  u k v1 c1 ... vk ck
 *  (※u：頂点番号)
 *  (※k：uの出次数)
 *  (※vi：uに隣接する頂点の番号)
 *  (※ci：uとviをつなぐ有向辺の重み)
 *
    5
    0 3 2 3 3 1 1 2
    1 2 0 2 3 4
    2 3 0 3 3 1 4 1
    3 4 2 1 0 1 1 4 4 3
    4 2 2 1 3 3
 *
 *
 * ex)matrixAdj
 * [0]：(2,3) (3,1) (1,2)
 * [1]：(0,2) (3,4)
 * [2]：(0,3) (3,1) (4,1)
 * [3]：(2,1) (0,1) (1,4) (4,3)
 * [4]：(2,1) (3,3)
 *
 *  出力例：
 *  各頂点の番号：v 　距離：d[v]
    0 0
    1 2
    2 2
    3 1
    4 3
 */
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;

#define MAX_APEX_NUM 10000
//隣接先が存在しない
#define INFTY 1000000
//未訪問
#define WHITE 0
//確定
#define BLACK 1

#define CHANGE_ASCENDING -1

//Debug
void PrintDebugNowMinDst(const  vector<int>& now_min_distance, const int apex_num){
	  for (int idx = 0; idx < apex_num; ++idx) {
		  cout << "[" << idx << "] : " << now_min_distance[idx] << endl;
	  }
}

void initialize(priority_queue<pair<int, int>>& PQ, int *color, int apexNum){
  for ( int i = 0; i < apexNum; i++ ){
    color[i] = WHITE;
  }
  PQ.push(make_pair(0, 0));
}
/* ex)matrixAdj ∞を設定しなくてよい
 * [0]：(2,3) (3,1) (1,2)
 * [1]：(0,2) (3,4)
 * [2]：(0,3) (3,1) (4,1)
 * [3]：(2,1) (0,1) (1,4) (4,3)
 * [4]：(2,1) (3,3)
 *
 * ex)idxTarget
 *                 0 → 3 → 2 → 1 → 4 → 2 → 4
 * ex)now_min_distance
 * [0]：0  → 0 → 0 → 0 → 0 → 0 → 0 → 0
 * [1]：∞ → 2 → 2 → 2 → 2 → 2 → 2 → 2
 * [2]：∞ → 3 → 2 → 2 → 2 → 2 → 2 → 2
 * [3]：∞ → 1 → 1 → 1 → 1 → 1 → 1 → 1
 * [4]：∞ →∞ → 4 → 3 → 3 → 3 → 3 → 3
 */
void updateNowDst(const vector<pair<int, int>> MatrixAdj[MAX_APEX_NUM], priority_queue<pair<int, int>>& PQ,
		vector<int>* now_min_distance, int *color, int idxTarget, int apexNum){
  for ( int j = 0; j < (int)MatrixAdj[idxTarget].size(); j++ ){
	int idx_adj = MatrixAdj[idxTarget][j].first;
    if ( color[idx_adj] == BLACK ) continue;
    /* nowDstを更新したら更新した重みをキューに詰め込む
     * nowDst(.first)が昇順になるよう並び替える
     * -1：降順防止
     */
    //説明変数
    int distance_via_idx_target = (*now_min_distance)[idxTarget] + MatrixAdj[idxTarget][j].second;
    if ( (*now_min_distance)[idx_adj] > distance_via_idx_target){
    	(*now_min_distance)[idx_adj] = distance_via_idx_target;
    	PQ.push(make_pair((*now_min_distance)[idx_adj] * CHANGE_ASCENDING, idx_adj));
    }
  }
//  PrintDebugNowMinDst((*now_min_distance), apexNum);
}

void dijkstra(vector<pair<int, int>> adj[MAX_APEX_NUM], const int apexNum){
  //pair<重み,更新要素番号>
  priority_queue<pair<int, int> > PQ;
  int color[MAX_APEX_NUM];
  //各データの初期化
  initialize(PQ,color, apexNum);

  vector<int> now_min_distance(apexNum,INFTY);
  now_min_distance[0] = 0;

  while(!PQ.empty()){
    /*先頭（dstの一番小さい要素番号）を取り出す*/
    //初回は(0,0)
    pair<int, int> tmpQueHead = PQ.top();
    PQ.pop();

    int idxTarget = tmpQueHead.second;
    //ForDebug
//    cout << "idx : " << idxTarget <<endl;

    color[idxTarget] = BLACK;

	updateNowDst(adj, PQ, &now_min_distance, color, idxTarget, apexNum);
  }

  /*output*/
  for ( int i = 0; i < apexNum; i++ ){
    cout << i << " " << now_min_distance[i] << endl;
  }
}

void createMatrixWeight(vector<pair<int, int> > matrixAdj[MAX_APEX_NUM], int apexNum){
  int apexData, adjNum, adjoinApex, weight;
  for ( int i = 0; i < apexNum; i++ ){
    cin >> apexData >> adjNum;
    for ( int j = 0; j < adjNum; j++ ){
      cin >> adjoinApex >> weight;
      matrixAdj[apexData].push_back(make_pair(adjoinApex, weight));
    }
  }
}


int main(){
    int apexNum;
    cin >> apexNum;
    //pair<隣接番号,隣接番号との重み>
    vector<pair<int, int> > matrixAdj[MAX_APEX_NUM];
	createMatrixWeight(matrixAdj, apexNum);


    dijkstra(matrixAdj,apexNum);

    return 0;
}


Compiler output:
a.cc:213:6: error: redefinition of 'void PrintDebugNowMinDst(const std::vector<int>&, int)'
  213 | void PrintDebugNowMinDst(const  vector<int>& now_min_distance, const int apex_num){
      |      ^~~~~~~~~~~~~~~~~~~
a.cc:69:6: note: 'void PrintDebugNowMinDst(const std::vector<int>&, int)' previously defined here
   69 | void PrintDebugNowMinDst(const  vector<int>& now_min_distance, const int apex_num){
      |      ^~~~~~~~~~~~~~~~~~~
a.cc:303:5: error: redefinition of 'int main()'
  303 | int main(){
      |     ^~~~
a.cc:144:5: note: 'int main()' previously defined here
  144 | int main() {
      |     ^~~~