A graph problem
I am struggling to solve the following problem

http://uva.onlinejudge.org/external/1/193.html

However Im not able to get a fast solution.

And as seen by the times of others, there should be a solution of maximum n^2 complexity

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problemid=129&page=problem_stats

Can I get some help?
A graph problem
===

I am struggling to solve the following problem

http://uva.onlinejudge.org/external/1/193.html

However Im not able to get a fast solution.

And as seen by the times of others, there should be a solution of maximum n^2 complexity

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problemid=129&page=problem_stats

Can I get some help?