算法思想: 类似最小生成树的贪心算法,从起点 v0 每次新拓展一个距离最小的点,再以这个点为中间点,更新起点到其他点的距离. 算法实现: 需要定义两个一维数组:①vis[ i ] 表示是否从源点到顶点 i 的最短距离.②用d[ i ] 记录源点v0到顶点 i 的距离值. 具体步骤如下: (1)初始化 d[ v0 ] = 0 ,源点v0到其他点的距离值 d[ i ] = ∞ . (2)经过 n 次如下操作,最后得到 v0 到 n 个顶点的最短距离: ①选择一个未标记的点 v 并且 d[ v ]…
Dijkstra struct node { long long x,d; node(); node(long long xx,long long dd){ x = xx; d = dd; } }; vector<node> edge[maxn]; void dijkstra(long long x) { long long i,j; for(i=0;i<n;i++) vis[i] = 0,dis[i] = INF; dis[x] = 0; for(i=0;i<n;i++){ lo…
最短路 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 33657 Accepted Submission(s): 14617 Problem Description 在每年的校赛里,全部进入决赛的同学都会获得一件非常美丽的t-shirt.可是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的! 所以如今他们想要…
题目传送:http://hihocoder.com/problemset/problem/1081 #include<iostream> #include<cstdio> #include<cstring> #define INF 0x03F3F3F3F #define N 1024 int path[N], vis[N]; int cost[N][N],lowcost[N]; void Dijkstra(int n, int beg){ int i, j, min;…
Description Problem D: Airport Express In a small city called Iokh, a train service, Airport-Express, takes residents to the airport more quickly than other transports. There are two types of trains in Airport-Express, the Economy-Xpress and the Comm…
Description Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie needs her beauty sleep, so she wants to get back as quickly as possible. Farmer Joh…
普通dijkstra,复杂度O(n*n) #include<bits/stdc++.h> using namespace std; int n,m,f[105][105],dis[105]; bool b[105]; //n为总共的点数,m为路径数,f数组记录两个点的距离,dis数组记录每个点到原点的距离 int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=m;i++){ int aa,bb,cc; scan…
MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6499 Accepted: 4036 Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchic…