Functions to handle graphs in C