Thursday, October 18, 2018

[POJ]Stockbroker Grapevine



Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst the stockbrokers to give your employer the tactical edge in the stock market. For maximum effect, you have to spread the rumours in the fastest possible way.

Unfortunately for you, stockbrokers only trust information coming from their "Trusted sources" This means you have to take into account the structure of their contacts when starting a rumour. It takes a certain amount of time for a specific stockbroker to pass the rumour on to each of his colleagues. Your task will be to write a program that tells you which stockbroker to choose as your starting point for the rumour, as well as the time it will take for the rumour to spread throughout the stockbroker community. This duration is measured as the time needed for the last person to receive the information.

这道题本质上就是根据输入建图,然后我们需要求的就是在图中找到一个节点v,从v到达其他所有节点的最长路径是最短的。在这篇文章我们讲解过,Floyd可以求解多源最短路径问题,我们只需要跑一遍Floyd,然后对于每个节点v找相距最远的距离,然后取最小的v即可。时间复杂度O(V^3),代码如下:

No comments:

Post a Comment