标签:
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.
Sample Input
3
Sample Output
3 2
Source
Southern African 2001
题目大意:有N个股票经济人,他们之间可以传递信息,但是他们只相信他们认为可靠的人的信息。
现在由某个人开始传信息,怎么能在最短的时间内让所有人都接收到消息。这个时间取决于最后一
个人收到信息的时间。如果没有一个人能使所有人都接收到信息,则输出"disjoint",否则,就输出
最短的时间和这个人的编号。
思路:可以看做是N个点,M条单向边。建立一个图,然后用Floyd求多源最短路径。之后,遍历所
有的结点,找到符合要求的那个人编号。不存在就输出"disjoint"。
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> using namespace std; const int MAXN = 110; const int INF = 0xffffff0; int Map[MAXN][MAXN], Dist[MAXN][MAXN]; void Floyd(int N) { for(int i = 1; i <= N; ++i) { for(int j = 1; j <= N; ++j) Dist[i][j] = Map[i][j]; } for(int k = 1; k <= N; ++k) { for(int i = 1; i <= N; ++i) { for(int j = 1; j <= N; ++j) { if(Dist[i][k] != INF && Dist[k][j] != INF && Dist[i][k] + Dist[k][j] < Dist[i][j]) Dist[i][j] = Dist[i][k] + Dist[k][j]; } } } } int main() { int N; while(~scanf("%d",&N) && N) { for(int i = 1; i <= N; ++i) for(int j = 1; j <= N; ++j) Map[i][j] = INF; for(int i = 1; i <= N; ++i) { int d; scanf("%d",&d); while(d--) { int to,dist; scanf("%d%d",&to,&dist); Map[i][to] = dist; } } Floyd(N); int ans = INF,pos,tMin; for(int i = 1; i <= N; ++i) { int flag = 0; tMin = 0; for(int j = 1; j <= N; ++j) { if(i != j && Dist[i][j] == INF) { flag = 1; break; } if(i != j && Dist[i][j] > tMin) { tMin = Dist[i][j]; } } if(flag == 0 && tMin < ans) { ans = tMin; pos = i; } } if(ans == INF) printf("disjoint\n"); else printf("%d %d\n",pos,ans); } return 0; }
POJ1125 Stockbroker Grapevine【Floyd】
标签:
原文地址:http://blog.csdn.net/lianai911/article/details/43119411