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
- Cap input at 100 vertices.
- Raise MAX_SIZE and recompile (O(MAX_SIZE^2) memory).
- 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
- Treat MAX_SIZE as a hard contract; assert before each addVertex in debug.
- Choose the adjacency-list variant for graphs that may exceed 100 nodes.
- Wrap addVertex in a status-returning helper so failures are detectable beyond stderr.
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
- 图的顶点数量已达最大值
- Graph vertex count has reached maximum
- グラフの頂点数が最大値に達しました
- 圖的頂點數量已達最大值
- индекс вершины выходит за границы
AI-assisted analysis of krahets/hello-algo@69932aed18 (2026-08-13).
Data as JSON: /api/errors/6671bb6ccd50bdce.
Report an issue: GitHub.