It's fine to ask questions about homework or contests, as long as the questions are complete and on-topic.

This one is a "fix my code" question without showing any code, so:

> Off-topic: Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.

The're another question, linked from the comments, about the same subject: http://stackoverflow.com/questions/35250604/correctness-of-algorithm-for-finding-diameter-of-graph. This one is too broad, because this is the entire problem statement:

> Can anyone prove its correctness or prove it is false