krahets/hello-algo · error
グラフの頂点数が最大値に達しました
Error message
グラフの頂点数が最大値に達しました
What it means
Japanese localization of the addVertex capacity check (see error 600). The adjacency-matrix graph holds at most MAX_SIZE (100) vertices in fixed compile-time-sized arrays; on the 101st insertion addVertex writes this message to stderr and returns void without inserting.
Source
Thrown at ja/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 行目と n 列目を 0 にする
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
- Limit input to 100 vertices, pruning or partitioning beforehand.
- Increase #define MAX_SIZE and recompile (memory scales O(MAX_SIZE^2)).
- Use 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 (100) as a hard contract; assert before each addVertex in debug builds.
- Pick the adjacency-list implementation up front for graphs that may exceed 100 nodes.
- Wrap addVertex in a helper returning a status code so failures are detectable beyond stderr.
When it happens
Trigger: addVertex(graph, val) called when graph->size == 100. Any insertion beyond the fixed cap triggers it.
Common situations: Loading more than 100 nodes into the teaching graph; benchmarks exceeding the illustrative limit; assuming dynamic growth when the structure is fixed-size.
Related errors
- 图的顶点数量已达最大值
- Graph vertex count has reached maximum
- Количество вершин графа уже достигло максимума
- 圖的頂點數量已達最大值
- 頂点インデックスが範囲外です
AI-assisted analysis of krahets/hello-algo@69932aed18 (2026-08-13).
Data as JSON: /api/errors/7d06880c1bc68bb8.
Report an issue: GitHub.