第21271题 单选题
给定使用出边邻接表实现的带权无向图C++程序,求顶点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;
}
A

12

B

11

C

10

D

9

程序运行统计
暂无判题统计