MPI Maelstrom
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 12087   Accepted: 7464

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

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator

 #include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <cstring>
#include <cstdlib>//atoi的头文件
using namespace std;
#define P pair<int,int>
#define ph push_back
#define ll long long
#define M 4400
#define fi first
#define se second
const int inf=0x3f3f3f3f;
char s[];
int g[][];
int dp[];
int vis[];
int n;
queue<int>que;
void init()
{
for(int i=;i<=n;i++)
{
dp[i]=inf;
for(int j=;j<=n;j++)
{
if(i==j){
g[i][j]=;
}
else{
g[i][j]=inf;
}
}
}
while(!que.empty()){
que.pop();
}
}
void spfa(int sta)
{
vis[sta]=;
que.push(sta);
dp[sta]=;
while(!que.empty()){
int v=que.front();
que.pop();
vis[v]=;
for(int i=;i<=n;i++)
{
if(dp[i]>dp[v]+g[v][i]){
dp[i]=dp[v]+g[v][i];
if(!vis[i]){
vis[i]=;
que.push(i);
}
}
}
}
}
int main()
{
scanf("%d",&n);
init();
for(int i=;i<=n;i++)
{
for(int j=;j<i;j++)
{
scanf("%s",s);
int x=atoi(s);
if(x)
{
g[i][j]=x;
g[j][i]=g[i][j];
}
}
}
spfa();
int maxx=-;
for(int i=;i<=n;i++)
{
maxx=max(maxx,dp[i]);
}
printf("%d\n",maxx);
return ;
}

poj 1502的更多相关文章

  1. 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 ...

  2. poj 1502 最短路+坑爹题意

    链接:http://poj.org/problem?id=1502 MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Subm ...

  3. POJ 1502 MPI Maelstrom (Dijkstra)

    题目链接:http://poj.org/problem?id=1502 题意是给你n个点,然后是以下三角的形式输入i j以及权值,x就不算 #include <iostream> #inc ...

  4. POJ 1502 MPI Maelstrom(最短路)

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

  5. [poj 1502]昂贵的聘礼

    一道不算太难的最短路喵~ 容我吐槽一下,酋长的地位居然不是最高的额——那你特么的居然还算是酋长?! 枚举一个地位区间 [i..i+M-1] 只要所有的交易者的地位都在该区间中,那么就不会引起冲突 而这 ...

  6. POJ 1502 MPI Maelstrom

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

  7. kuangbin_ShortPath G (POJ 1502)

    尽管题目很长 写的很玄乎 让我理解了半天 但是事实上就是个模板题啊摔 一发水过不解释 #include <iostream> #include <string> #includ ...

  8. POJ 1502 MPI Maelstrom (最短路)

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

  9. POJ 1502 MPI Maelstrom( Spfa, Floyd, Dijkstra)

    题目大意: 给你 1到n ,  n个计算机进行数据传输, 问从1为起点传输到所有点的最短时间是多少, 其实就是算 1 到所有点的时间中最长的那个点. 然后是数据 给你一个n 代表有n个点, 然后给你一 ...

  10. 【单源最短路】dijstra poj 1502

    #include <cstdio> #include <iostream> #include <stdlib.h> #include <memory.h> ...

随机推荐

  1. python+selenium 页面中存在选项卡时,获取页面内容的小技巧

    最近用selenium读取页面内容时,遇到包含选项卡的页面,由于选项卡多由js加载其中的内容,所以在网址打开时只能获取到默认显示的选项卡中的内容,而tab2.tab3等等都需要傻傻的点击一下才会获取到 ...

  2. Django 使用Paginator分页

    from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger subclass_s = models.subclas ...

  3. vuex 使用方法

    1.安装vuex扩展 : npm install vuex 2.在componets目录下新建 store.js 文件 import Vue from 'vue' import Vuex from ' ...

  4. 原生ajax提交php后台接收不到问题

    var xmlHttp; if (window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); ...

  5. [转]Formatting the detail section to display multiple columns (水晶报表 rpt 一页多列)

    本文转自:http://www.bofocus.com/formatting-the-detail-section-to-display-multiple-columns/ Format the de ...

  6. sql server技巧

    --查出数据最新的存储过程select name,modify_date from sys.procedures where modify_date>'2017-05-26 17:21:09.3 ...

  7. nodejs json

    var express = require('express');var router = express.Router(); /* GET home page. */ router.get('/', ...

  8. (转)Linux下清理Cache方法

    频繁的文件访问会导致系统的Cache使用量大增, 系统运行缓慢. 1 首先用free 命令查看内存的使用:$ free -m             total       used       fr ...

  9. Sqlserver 2012 Always on技术

    使用了Sqlserver 2012 Always on技术后,假如采用的配置是默认配置,会出现Primary server CPU很高的情况发生,比如默认配置如下: 需要自定义来解决这个问题. 我们先 ...

  10. ajax传给springMVC数据编码集问题

    前台 ajax: $.ajax("${pageContext.request.contextPath}/hello",// 发送请求的URL字符串. { dataType : &q ...