POJ-1502 MPI Maelstrom
来源:互联网 发布:永恒之柱 知乎 编辑:程序博客网 时间:2024/05/16 06:34
题目链接:https://vjudge.net/problem/POJ-1502
给出n个节点的连通图,求从1点到其他所有点的最短路,再输出其中最远的那个,这里用dijkstra做
输入以邻接矩阵下三角的方式给出,注意如果没有相连以字符‘x’表示,处理时需要一些输入技巧
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<sstream>using namespace std;const int N=100+2;const int inf=0x7f7f7f7f;struct node{int pos;int dist;node(int a,int b){pos=a;dist=b;}bool operator < (const node &u) const{return dist<u.dist;}};int n;int g[N][N],d[N];int main(){string a;int b;while(~scanf("%d",&n)){memset(g,0,sizeof(g));for(int i=0;i<n;i++)for(int j=0;j<i;j++){cin>>a;if(a[0]=='x')g[i][j]=g[j][i]=inf;else{stringstream s;s<<a;s>>b;g[i][j]=g[j][i]=b;}}memset(d,inf,sizeof(d));priority_queue<node> q;q.push(node(0,0));d[0]=0;while(!q.empty()){node u=q.top();q.pop();int p=u.pos;for(int i=0;i<n;i++)if(d[i]>d[p]+g[p][i]){d[i]=d[p]+g[p][i];q.push(node(i,d[i]));}}int ans=0;for(int i=1;i<n;i++)if(d[i]>ans) ans=d[i];printf("%d\n",ans);}return 0;}
阅读全文
0 0
- POJ 1502 MPI Maelstrom
- poj 1502 MPI Maelstrom
- POJ 1502 MPI Maelstrom
- poj 1502 MPI Maelstrom
- poj 1502 MPI Maelstrom
- poj 1502 MPI Maelstrom
- poj 1502 MPI Maelstrom
- POJ-1502-MPI Maelstrom
- poj 1502 MPI Maelstrom
- POJ 1502 MPI Maelstrom
- poj 1502 MPI Maelstrom
- poj 1502 MPI Maelstrom
- poj 1502 MPI Maelstrom
- POJ 1502 MPI Maelstrom
- poj 1502:MPI Maelstrom
- poj 1502: MPI Maelstrom
- POJ 1502 MPI Maelstrom
- poj-1502 MPI Maelstrom
- linux最大文件句柄数量总结
- Linux VIM编辑器常用命令
- navicat 连接不上数据库(一台机器 访问 另外一台机器)
- NoSuchMethodError aop.support.AopUtils.selectInvocableMethod(Ljava/lang/reflect/Method;Ljava/lang/Cl
- JavaScript学习-Function类型
- POJ-1502 MPI Maelstrom
- 树形DP
- Android--文件压缩及文件解压
- 微信小程序开发系列(一) ——怎样开始进入小程序开发
- leetcode 433. Minimum Genetic Mutation 和Word Ladder一样BFS + 反向链表 + DFS
- 欢迎使用CSDN-markdown编辑器
- 水冷或风冷的数据中心?
- 架构模式 MVC、MVP、MVVM 的区别与联系
- Greenplum 清理垃圾、修改存储模式(行列变换) 平滑方法