测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A23843. 下面的程序使用出边邻接表表达的带权无向图,则从顶点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_…

单选题 困难

题目描述

下面的程序使用出边邻接表表达的带权无向图,则从顶点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;
}

选项(单选)

上一题 下一题