POJ 1125 Stockbroker Grapevine
来源:互联网 发布:淘宝开店需要保证金吗 编辑:程序博客网 时间:2024/06/05 20:17
Description
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.
【题目分析】
是要求一个点,走到其他所有点的路径长度的和的最小值。由于有很多个源点,只能用floyd跑一边,然后再暴力的统计一下就好了。
【代码】
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;int n,m,b,c,dis[101][101];int main(){ while (cin>>n&&n) { memset(dis,0x3f,sizeof dis); for (int i=1;i<=n;++i) dis[i][i]=0; for (int i=1;i<=n;++i) { cin>>m; for (int j=1;j<=m;++j) cin>>b>>c,dis[i][b]=min(dis[i][b],c); } for (int k=1;k<=n;++k) for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]); int ans=0x3f3f3f3f,ai=-1; for (int i=1;i<=n;++i) { int tmp=0; for (int j=1;j<=n;++j) tmp=max(dis[i][j],tmp); if (tmp<ans) ai=i; ans=min(ans,tmp); } if (ans==0x3f3f3f3f) cout<<"disjoint"<<endl; else cout<<ai<<" "<<ans<<endl; }}
- poj 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- poj 1125 Stockbroker Grapevine
- poj 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- poj 1125 Stockbroker Grapevine
- Poj 1125 Stockbroker Grapevine
- poj 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- poj 1125-Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- poj 1125 Stockbroker Grapevine
- poj 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- 欢迎使用CSDN-markdown编辑器
- POJ 3177 Redundant Paths
- poj3669【bfs】
- 九大排序算法之代码实现
- CodeForces 55D Beautiful numbers(数位dp)
- POJ 1125 Stockbroker Grapevine
- mysql默认连接超时问题的解决方法
- mac下eclipse配置tomcat
- (三十)、Collection接口
- 读《About Face 4 交互设计精髓》4
- 通过串口下载Simplelink examples 固件
- 2016.08.13【初中部 NOIP提高组 】模拟赛C
- 【JQuery】入门基础总结
- 在多线程环境中使用CoreData