11.20
import java.util.*;
// 1. 边类:存储目标顶点和权重
class Edge {
int targetVertex; // 目标顶点的索引
int weight; // 边的权重(无权图可设为1)
public Edge(int targetVertex, int weight) {
this.targetVertex = targetVertex;
this.weight = weight;
}
}
// 2. 图类(邻接表实现)
class Graph {
private List
private List<List
// 初始化空图
public Graph() {
vertices = new ArrayList<>();
adjacencyList = new ArrayList<>();
}

浙公网安备 33010602011771号