Not able to get a proper approach

Hii…
I am doing this question from hackerearth…

I have understood the question and i have also got the main logic i.e, -.
The main concept is if you have atleast one edge which is not the part of any possible diameter then you can put S to that edge hence ans is 0. Else you will put S / (n-1) to each edge. Note that, its ceil will be the minimum possible maximum edge weight. Thus, the task is just to find that one edge which is not the part of any possible diameter.

But i am not able to get an approch… How to code it…
Please see this …
Thanks…