参考挑战程序设计竞赛(第2版)——人民邮电出版社中的写法
Dijkstra
#include<iostream>
using namespace std;
#define MAX_V 10
#define INF 9999
int main() {
int cost[MAX_V][MAX_V] = {
0 };
int d[MAX_V] = {
0 };
bool used[MAX_V] = {
false };
int V = 0;
cout << "输入顶点个数:" << " ";
cin >> V;
for (int i = 0; i < V; i++)
{
d[i] = INF;
//cout << d[i] << "/ ";
//cout << used[i] << " ";
}
for (int i = 0; i < V; i++)
{
for (int j = 0; j < V; j++)
{
cout << "邻接表第" << i + 1 << "行,第" << j + 1<< "列:";
cin >> cost[i][j];
}
}
cout << "输入源点s:" << " ";
int s = 0;
cin >> s;
d[s] = 0;
while (true)
{
int v = -1;
for