krahets/hello-algo · error

Количество вершин графа уже достигло максимума

Error message

Количество вершин графа уже достигло максимума

What it means

Russian localization of the addVertex capacity check (see error 600). The graph is bounded by #define MAX_SIZE 100 in fixed arrays; the 101st addVertex prints this to stderr and returns void without inserting.

Source

Thrown at ru/codes/c/chapter_graph/graph_adjacency_matrix.c:39

    GraphAdjMat *graph = (GraphAdjMat *)malloc(sizeof(GraphAdjMat));
    graph->size = 0;
    for (int i = 0; i < MAX_SIZE; i++) {
        for (int j = 0; j < MAX_SIZE; j++) {
            graph->adjMat[i][j] = 0;
        }
    }
    return graph;
}

/* Деструктор */
void delGraphAdjMat(GraphAdjMat *graph) {
    free(graph);
}

/* Добавление вершины */
void addVertex(GraphAdjMat *graph, int val) {
    if (graph->size == MAX_SIZE) {
        fprintf(stderr, "Количество вершин графа уже достигло максимума\n");
        return;
    }
    // Добавить n-ю вершину и обнулить n-ю строку и столбец
    int n = graph->size;
    graph->vertices[n] = val;
    for (int i = 0; i <= n; i++) {
        graph->adjMat[n][i] = graph->adjMat[i][n] = 0;
    }
    graph->size++;
}

/* Удаление вершины */
void removeVertex(GraphAdjMat *graph, int index) {
    if (index < 0 || index >= graph->size) {
        fprintf(stderr, "индекс вершины выходит за границы\n");
        return;
    }
    // Удалить вершину с индексом index из списка вершин

View on GitHub (pinned to 69932aed18)

Solutions

  1. Cap input at 100 vertices.
  2. Raise MAX_SIZE and recompile (O(MAX_SIZE^2) memory).
  3. Switch to the adjacency-list implementation for larger graphs.

Example fix

// before
for (int i = 0; i < 1000; i++) addVertex(graph, i);

// after
for (int i = 0; i < 1000 && graph->size < MAX_SIZE; i++) addVertex(graph, i);
Defensive patterns

Strategy: validation

Validate before calling

static inline int graphCanAddVertex(const GraphAdjMat *g) {
    return g != NULL && g->size < MAX_SIZE;
}

if (graphCanAddVertex(graph)) addVertex(graph, val);

Prevention

When it happens

Trigger: addVertex(graph, val) when graph->size == 100.

Common situations: Datasets larger than 100 nodes; stress tests past the cap; assuming dynamic resizing.

Related errors


AI-assisted analysis of krahets/hello-algo@69932aed18 (2026-08-13). Data as JSON: /api/errors/6671bb6ccd50bdce. Report an issue: GitHub.