Apparently, the add_edge(1,3,G)
call adds vertices to the graph if needed. Your first call is in that case. Then it adds the edge from vertex 1 to vertex 3. Note that after this call, the number of vertices is 4, since the vertices are then indexed from 0 to 3.
The subsequent call to remove_edge(1,3,G)
removes the edge that was just added, but leaves the number of vertices unchanged.
The call to edge(1,3,G)
on the other hand does not add any vertex to the graph, the boolean in the return is there to state if vertices 1 and 3 are connected or not. There is an access violation is you remove the add_edge
because the vertices at index 1 and 3 do not exist.
You can simply initialize the graph with the desired number of vertices:
graph_t G(4);