#4383. [GESP202509 八级 C++] 第 15 题

[GESP202509 八级 C++] 第 15 题

下面的程序使用出边邻接表表达的带权无向图,则从顶点 0 到顶点 3 的最短距离为( )。

#include <vector>
using namespace std;
class Edge {
public:
    int dest;
    int weight;
    Edge(int d, int w) : dest(d), weight(w) {}
};
class Graph {
private:
    int num_vertex;
    vector<vector<Edge>> vve;
public:
    Graph(int v) : num_vertex(v), vve(v) {}
    void addEdge(int s, int d, int w) {
        vve[s].emplace_back(d, w);
        vve[d].emplace_back(s, w)
    }
};
int main() {
    Graph g(4);
    g.addEdge(0, 1, 8);
    g.addEdge(0, 2, 5);
    g.addEdge(1, 2, 1);
    g.addEdge(1, 3, 3);
    g.addEdge(2, 3, 7);
    return 0;
}

{{ select(1) }}

  • 12
  • 11
  • 10
  • 9