POJ1502 MPI Maelstrom Dijkstra

题意

给出图,从点1出发,求到最后一个点的时间。

思路

单源最短路,没什么好说的。注意读入的时候的技巧。

代码

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 1000000000;
const int maxn = 110;
int n;
int edge[maxn][maxn];
int d[maxn];
bool used[maxn];
void dijkstra(int s)
{
    d[s] = 0;
    while(true) {
        int v = -1;
        for(int i = 1 ; i <= n ; i ++) {
            if(!used[i]) {
                if(v == -1 || d[i] < d[v]) v = i;
            }
        }
        if(v == -1) break;
        used[v] = true;
        for(int i = 1 ; i <= n ; i ++) {
            d[i] = min(d[i],d[v]+edge[v][i]);
        }
    }
}
int main()
{
    //freopen("in.txt","r",stdin);
    fill(d,d+maxn,INF);
    memset(used,false,sizeof(used));
    for(int i = 0 ; i < maxn ; i ++) {
        fill(edge[i],edge[i]+maxn,INF);
        edge[i][i] = 0;
    }
    scanf("%d",&n);
    for(int i = 2 ; i <= n ; i ++) {
        for(int j = 1 ; j < i ; j ++) {
            int tmp;
            char getit;
            if(scanf("%d",&tmp))
                edge[i][j] = edge[j][i] = tmp;
            else scanf("%c",&getit);
        }
    }
    dijkstra(1);
    int ma = d[1];
    for(int i = 2 ; i <= n ; i ++) {
        ma = max(d[i],ma);
    }
    cout << ma << endl;
    return 0;
}
时间: 2024-10-10 14:59:21

POJ1502 MPI Maelstrom Dijkstra的相关文章

poj 1502 MPI Maelstrom Dijkstra算法的简单运用 ,呵呵,,我估计有很多人都没看懂什么意思,我也看了很久

MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5831   Accepted: 3621 Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchic

POJ 1502 MPI Maelstrom (Dijkstra 模板题)

MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5877   Accepted: 3654 Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchic

poj1502——MPI Maelstrom(dijkstra算法)

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 be

poj1502 MPI Maelstrom,单源最短路的最长距离,dijkstra + 优先队列

点击打开链接 求顶点1到其他点的最短距离的最长距离.. 测试..dijkstra + 优先队列 #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <set> #include <map> #include <string> #include <sta

POJ1502: MPI Maelstrom

红果果的dijstra算法应用,这里采用邻接表存储图. 小插曲:while(scanf("%d",&n))提交时内存超限,改成while(scanf("%d",&n)!=EOF)就AC了,不知道为什么 dijstra算法应用:已知定点为输入,输入图中所有其他点到该定点的最短距离. 具体做法: a.初始时,S只包含源点,即S={v},v的距离为0.U包含除v外的其他顶点,即:U={其余顶点},若v与U中顶点u有边,则<u,v>正常有权值,若

poj1502 MPI Maelstrom(单源最短路)

题意:表面乍一看output是输出最小值,但仔细研究可以发现,这个最小值是从点1到所有点所花时间的最小值,其实是访问这些节点中的最大值,因为只有访问了最长时间的那个点才算访问了所有点.所以求最短路之后求最大值. #include <iostream> #include <cstring> #include <cstdio> using namespace std; const int maxn = 100 + 5; const int inf = 0x3f3f3f3f;

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

MPI Maelstrom 总时间限制:  1000ms 内存限制:  65536kB 描述 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

POJ 1502 MPI Maelstrom [最短路 Dijkstra]

传送门 MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5711   Accepted: 3552 Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierar

MPI Maelstrom(poj1502)(迪杰斯特拉+atoi函数)

MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5637   Accepted: 3513 Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchic