{"record":{"id":"083bdcdf1d64417c","repo":"TheAlgorithms/Go","slug":"coloring-same-colors-of-neighbouring-vertex","errorCode":null,"errorMessage":"coloring: same colors of neighbouring vertex","messagePattern":"coloring: same colors of neighbouring vertex","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graph/coloring/graph.go","lineNumber":52,"sourceCode":"func (g *Graph) AddEdge(one, two int) {\n\t// Add vertices: one and two to the graph if they are not present\n\tg.AddVertex(one)\n\tg.AddVertex(two)\n\n\t// and finally add the edges: one->two and two->one for undirected graph\n\tg.edges[one][two] = struct{}{}\n\tg.edges[two][one] = struct{}{}\n}\n\nfunc (g *Graph) ValidateColorsOfVertex(colors map[int]Color) error {\n\tif g.vertices != len(colors) {\n\t\treturn errors.New(\"coloring: not all vertices of graph are colored\")\n\t}\n\t// check colors\n\tfor vertex, neighbours := range g.edges {\n\t\tfor nb := range neighbours {\n\t\t\tif colors[vertex] == colors[nb] {\n\t\t\t\treturn errors.New(\"coloring: same colors of neighbouring vertex\")\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":34,"sourceCodeEnd":58,"githubUrl":"https://github.com/TheAlgorithms/Go/blob/5ba447ec5ff3d1213de65b92e726ee74c5d5cc19/graph/coloring/graph.go#L34-L58","documentation":"ValidateColorsOfVertex found two adjacent vertices assigned the same Color, violating proper coloring. This means the graph is not bipartite (when called from BipartiteCheck) or the supplied coloring is invalid.","triggerScenarios":"Thrown at graph/coloring/graph.go:52 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Recolor using a proper 2-coloring (BFS/DFS alternating colors) before validating","Treat the error as the answer to BipartiteCheck: the graph is not bipartite","Fix the coloring assignment so neighbours always differ"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5ba447ec5ff3d1213de65b92e726ee74c5d5cc19","analyzedAt":"2026-09-02T21:54:30.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}