{"record":{"id":"a5411275545b001c","repo":"krahets/hello-algo","slug":"error-a54112","errorCode":null,"errorMessage":"индексы ребра выходят за границы или совпадают\n","messagePattern":"индексы ребра выходят за границы или совпадают\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ru/codes/c/chapter_graph/graph_adjacency_matrix.c","lineNumber":80,"sourceCode":"    for (int i = index; i < graph->size - 1; i++) {\n        for (int j = 0; j < graph->size; j++) {\n            graph->adjMat[i][j] = graph->adjMat[i + 1][j];\n        }\n    }\n    // Удалить столбец с индексом index из матрицы смежности\n    for (int i = 0; i < graph->size; i++) {\n        for (int j = index; j < graph->size - 1; j++) {\n            graph->adjMat[i][j] = graph->adjMat[i][j + 1];\n        }\n    }\n    graph->size--;\n}\n\n/* Добавление ребра */\n// Параметры i и j соответствуют индексам элементов vertices\nvoid addEdge(GraphAdjMat *graph, int i, int j) {\n    if (i < 0 || j < 0 || i >= graph->size || j >= graph->size || i == j) {\n        fprintf(stderr, \"индексы ребра выходят за границы или совпадают\\n\");\n        return;\n    }\n    graph->adjMat[i][j] = 1;\n    graph->adjMat[j][i] = 1;\n}\n\n/* Удаление ребра */\n// Параметры i и j соответствуют индексам элементов vertices\nvoid removeEdge(GraphAdjMat *graph, int i, int j) {\n    if (i < 0 || j < 0 || i >= graph->size || j >= graph->size || i == j) {\n        fprintf(stderr, \"индексы ребра выходят за границы или совпадают\\n\");\n        return;\n    }\n    graph->adjMat[i][j] = 0;\n    graph->adjMat[j][i] = 0;\n}\n\n/* Вывести матрицу смежности */","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/c/chapter_graph/graph_adjacency_matrix.c#L62-L98","documentation":"Russian localization of the addEdge guard (see error 602). addEdge rejects negative/out-of-range endpoints and forbids i == j (simple undirected graph, no self-loops). Logged to stderr; adjMat unchanged.","triggerScenarios":"addEdge(graph, i, j) with i/j out of range or equal — commonly vertex values used as indices, or a self-loop.","commonSituations":"Value-vs-index confusion; self-loops; edges before endpoints exist.","solutions":["Pass indices, not values.","Insert endpoints first.","Reject i == j at the call site."],"exampleFix":"// before\naddEdge(graph, 1, 3);\n\n// after\nint i = indexOf(graph, 1), j = indexOf(graph, 3);\nif (i >= 0 && j >= 0 && i != j) addEdge(graph, i, j);","handlingStrategy":"validation","validationCode":"static inline int graphValidEdge(const GraphAdjMat *g, int i, int j) {\n    return g != NULL && i >= 0 && j >= 0\n        && i < g->size && j < g->size && i != j;\n}\n\nif (graphValidEdge(graph, i, j)) addEdge(graph, i, j);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass indices, not values.","Insert endpoints before adding edges.","Forbid i == j at the call site."],"tags":["graph","bounds","edge","self-loop","adjacency-matrix","c","i18n-ru"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}