Your problem starts earlier by allocating G. G is your pointer array so you need the count of arrays. It is a pointer to an array of pointers. This
tutorial brings some insight. Your G is that
array of ptr.
struct graph *G=(struct graph **)malloc(sizeof(struct *graph) * count);
G[i]=(struct graph)malloc(sizeof(struct graph));
Another possible solution, when you have a fixed size of structs:
const int COUNT = 100; struct graph G[COUNT];
G[i][x] = 0;
Pointer to pointers is an confusing issue. You must understand that everything in C is in some memory. And the program is interpreting that memory to some values. This article is a nice
Beginner's Guide to Pointers.