1. 迪杰斯特拉算法求解图的最短路径
import java.util.Arrays;
import static main.Common.INF;
public class Dijkstra {
private int[][] path;
private int vertex;
public Dijkstra(int nodeNum, String[] src) {
path = new int[nodeNum][nodeNum];
for(int i = 0;i < nodeNum;i++) {
for(int j = 0;j < nodeNum;j++) {
path[i][j] = INF;
}
}
this.vertex = src.length;
for(String str : src) {
int[] data = Arrays.stream(str.split(" ")).mapToInt(Integer::parseInt).toArray();
path[data[0]][data[1]] = data[2];
path[data[1]][data[0]] = data[2];
}
}
/**
*
* @param vs 起始顶点
*/
public int[] process(int vs) {
int[] prev = new int[vertex];
int[] dist = new int[vertex];
boolean[] find = new bool