colorings – Distance-2 colouring – undirected graph using C

I have to write a program in C that takes a description of an undirected graph from stdin, and prints a distance-2 coloring for this graph to stdout. The coloring should use no more than d(d − 1) + 1 colors, where d is the maximum number of neighbors of any vertex in the graph.