Time Limit: 1000MS Memory Limit: 10000K

Description

BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchical communication subsystem. Valentine McKee’s research advisor, Jack Swigert, has asked her to benchmark the new system. Since the Apollo is a distributed shared memory machine, memory access and communication times are not uniform,” Valentine told Swigert. “Communication is fast between processors that share the same memory subsystem, but it is slower between processors that are not on the same subsystem. Communication between the Apollo and machines in our lab is slower yet.”

“How is Apollo’s port of the Message Passing Interface (MPI) working out?” Swigert asked.

Not so well,'' Valentine replied.To do a broadcast of a message from one processor to all the other n-1 processors, they just do a sequence of n-1 sends. That really serializes things and kills the performance.”

“Is there anything you can do to fix that?”

Yes,'' smiled Valentine.There is. Once the first processor has sent the message to another, those two can then send messages to two other hosts at the same time. Then there will be four hosts that can send, and so on.”

“Ah, so you can do the broadcast as a binary tree!”

“Not really a binary tree – there are some particular features of our network that we should exploit. The interface cards we have allow each processor to simultaneously send messages to any number of the other processors connected to it. However, the messages don’t necessarily arrive at the destinations at the same time – there is a communication cost involved. In general, we need to take into account the communication costs for each link in our network topologies and plan accordingly to minimize the total time required to do a broadcast.”

Input

The input will describe the topology of a network connecting n processors. The first line of the input will be n, the number of processors, such that 1 <= n <= 100.

The rest of the input defines an adjacency matrix, A. The adjacency matrix is square and of size n x n. Each of its entries will be either an integer or the character x. The value of A(i,j) indicates the expense of sending a message directly from node i to node j. A value of x for A(i,j) indicates that a message cannot be sent directly from node i to node j.

Note that for a node to send a message to itself does not require network communication, so A(i,i) = 0 for 1 <= i <= n. Also, you may assume that the network is undirected (messages can go in either direction with equal overhead), so that A(i,j) = A(j,i). Thus only the entries on the (strictly) lower triangular portion of A will be supplied.

The input to your program will be the lower triangular section of A. That is, the second line of input will contain one entry, A(2,1). The next line will contain two entries, A(3,1) and A(3,2), and so on.

Output

Your program should output the minimum communication time required to broadcast a message from the first processor to all the other processors.

Sample Input

5

50

30 5

100 20 50

10 x x 10

Sample Output

35

Source

East Central North America 1996

题意:有N个通讯器,他们之间有信息传递,但是传递的时间不同,有一个矩阵a[i,j]表示第i个通讯器向第j个通讯器之间传递信息需要的时间,x表示之间没有信息传递。问从第一个通讯器想其他的通讯器传递信息,所有通讯器都接受到信息的时间

分析:单源最短路模型,求出从第一个通讯器到其他的最短的时间的最大值就是结果。

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <queue>
  5. #include <stack>
  6. #include <queue>
  7. #include <vector>
  8. #include <cmath>
  9. #include <queue>
  10. #include <algorithm>
  11. #define LL long long
  12. using namespace std;
  13. const int Max = 110;
  14. const int INF = 0x3f3f3f3f;
  15. int Map[Max][Max];
  16. int Dis[Max];
  17. bool vis[Max];
  18. int n;
  19. char str[10];
  20. int Trans()
  21. {
  22. int ans = 0;
  23. for(int i = 0 ;str[i]!='\0';i++)
  24. {
  25. ans = ans*10+str[i]-'0';
  26. }
  27. return ans;
  28. }
  29. void SPFA()//SPFA求最短路
  30. {
  31. memset(vis,false,sizeof(vis));
  32. memset(Dis,INF,sizeof(Dis));
  33. vis[1]=true;
  34. Dis[1]=0;
  35. queue<int>Q;
  36. Q.push(1);
  37. while(!Q.empty())
  38. {
  39. int u = Q.front();
  40. Q.pop();
  41. vis[u]=false;
  42. for(int i=1;i<=n;i++)
  43. {
  44. if(Map[u][i]+Dis[u]<Dis[i])
  45. {
  46. Dis[i] = Map[u][i]+Dis[u];
  47. if(!vis[i])
  48. {
  49. vis[i]=true;
  50. Q.push(i);
  51. }
  52. }
  53. }
  54. }
  55. }
  56. int main()
  57. {
  58. int va;
  59. while(~scanf("%d",&n))
  60. {
  61. memset(Map,0,sizeof(Map));
  62. for(int i=2;i<=n;i++)
  63. {
  64. for(int j=1;j<i;j++)
  65. {
  66. scanf("%s",str);
  67. if(str[0]=='x')
  68. {
  69. va=INF;
  70. }
  71. else
  72. {
  73. va = Trans();
  74. }
  75. Map[i][j] = Map[j][i]=va;
  76. }
  77. }
  78. SPFA();
  79. int ans = 0;
  80. for(int i=2;i<=n;i++)
  81. {
  82. ans = max(ans,Dis[i]);
  83. }
  84. printf("%d\n",ans);
  85. }
  86. return 0;
  87. }

MPI Maelstrom - POJ1502最短路的更多相关文章

  1. POJ 1502 MPI Maelstrom(最短路)

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4017   Accepted: 2412 Des ...

  2. POJ-1502 MPI Maelstrom 迪杰斯特拉+题解

    POJ-1502 MPI Maelstrom 迪杰斯特拉+题解 题意 题意:信息传输,总共有n个传输机,先要从1号传输机向其余n-1个传输机传输数据,传输需要时间,给出一个严格的下三角(其实就是对角线 ...

  3. POJ 1502 MPI Maelstrom (最短路)

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6044   Accepted: 3761 Des ...

  4. MPI Maelstrom(East Central North America 1996)(poj1502)

    MPI Maelstrom 总时间限制:  1000ms 内存限制:  65536kB 描述 BIT has recently taken delivery of their new supercom ...

  5. POJ 1502 MPI Maelstrom [最短路 Dijkstra]

    传送门 MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5711   Accepted: 3552 ...

  6. POJ 1502 MPI Maelstrom

    MPI Maelstrom Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) Total ...

  7. POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom /ZOJ 1291 MPI Maelstrom (最短路径)

    POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom ...

  8. POJ1502(最短路入门题)

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7471   Accepted: 4550 Des ...

  9. POJ - 1502 MPI Maelstrom 路径传输Dij+sscanf(字符串转数字)

    MPI Maelstrom BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odys ...

随机推荐

  1. C#程序以管理员权限运行

    原文:C#程序以管理员权限运行 C#程序以管理员权限运行 在Vista 和 Windows 7 及更新版本的操作系统,增加了 UAC(用户账户控制) 的安全机制,如果 UAC 被打开,用户即使以管理员 ...

  2. nginx、fastCGI、php-fpm关系梳理(转)

    前言: Linux下搭建nginx+php+memached(LPMN)的时候,nginx.conf中配需要配置fastCGI,php需要安装php-fpm扩展并启动php-fpm守护进程,nginx ...

  3. wp8.1 VS2013部署手机发生 DEP6100 6200错误

    wp8.1 VS2013部署手机发生 DEP6100 6200错误 ,提示未发现手机. 可能是数据线有问题 建议更换 本人的电脑有很多次,提示DEP6100 6200错误,每一次都需要重做系统.. 然 ...

  4. sqlite3 命令

    然后使用下列操作打开并进入数据库 1 2 3 $./adb shell $cd sdcard/path/subdir $sqlite3 dsxniubility.db 终端内进入数据库一般操作也就是 ...

  5. laravel5.1学习(2)-- artisan tinker命令

    例如:为users表创建20条测试输入 G:\wamp\www\hcmf>php artisan tinker >>> namespace App; => null &g ...

  6. .NET编译项目时出现《此实现不是 Windows 平台 FIPS 验证的加密算法的一部分》处理方法

    有用户提出在编译代码时出现源文件“D:\.......ervice.cs”未能打开(“此实现不是 Windows 平台 FIPS 验证的加密算法的一部分.”)的问题,如下图所示: 对于上面的问题,只需 ...

  7. ubuntu14.04下安装python3.4.2

    1. python安装包的下载地址:https://www.python.org/downloads/ 我的python安装包下载地址:https://www.python.org/ftp/pytho ...

  8. GPS部标平台的架构设计(九)-GPS监控客户端设计

    交通部的部标过检,所有的测试都是从客户端发起的,也是在客户端体现的,在客户端承载了部标标准所要求的所有的功能,是整个部标平台当中工作量最大的部分,也是最繁琐的部分. 客户端设计面临两个问题: 1.基于 ...

  9. java基础类型、包装器

    char a = 'h';  //类包装器 Character aobj = a ;//自动装箱 byte b = 6; Byte bobj = b; short s = 234; Short sob ...

  10. redmine常见问题

    1.测试Pop3邮件收件任务:rake redmine:email:receive_pop3 RAILS_ENV="production" host=pop.cecgw.cn po ...