第28282题 单选题
如下C++代码实现了无向图的邻接表存储结构,关于该代码的描述正确的是?

以下代码实现了一个无向图的邻接表存储结构,关于该代码的说法正确的是:

#include <vector>
#include <stdexcept>
using namespace std;

class UndirectedGraph {
private:
    int vertexCount;
    vector<vector<int>> adjList;
public:
    UndirectedGraph(int n) : vertexCount(n), adjList(n) {}

    void addEdge(int u, int v) {
        if (u < 0 || u >= vertexCount || v <0 || v >= vertexCount) {
            throw out_of_range("顶点编号越界");
        }
        adjList[u].push_back(v);
        adjList[v].push_back(u);
    }

    int getDegree(int u) {
        return adjList[u].size();
    }
};
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析