题意:看半天题...给你半个矩阵,数字表示权值,x表示两点间不可达,由于自身到自身花费的时间为0,所以没有给出,由于i到j和j到i距离相同,互达时间相同,所以只给出了一半的临界矩阵。根据这个矩阵,让你来求从点1到其他点所花费最短时间集里面的的最大值。
思路:读懂题目之后其实这是一个裸最短路
#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <set>
#include <ctime>
#include <cmath>
#include <cctype>
using namespace std;
#define maxn 105
#define LL long long
int cas=1,T;
const int INF = 1<<29;
int n;
int mapp[maxn][maxn];
void dijkstra()
{
int min,v;
int ans = 0;
int d[maxn];
bool vis[maxn];
for (int i = 1;i<=n;i++)
{
vis[i]=0;
d[i]=mapp[1][i];
}
d[1]=0;
for (int i = 1;i<=n;i++)
{
min = INF;
for (int j = 1;j<=n;j++)
{
if (!vis[j] && d[j]<min)
{
min = d[j];
v = j;
}
}
vis[v]=1;
for (int j = 1;j<=n;j++)
if (!vis[j] && d[v]+mapp[v][j]<d[j])
d[j]=d[v]+mapp[v][j];
}
for (int i = 2;i<=n;i++)
ans = max(ans,d[i]);
printf("%d\n",ans);
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
for (int i = 0;i<=n;i++)
for (int j = 0;j<=n;j++)
if (i==j)
mapp[i][j]=0;
else
mapp[i][j]=mapp[j][i]=INF;
for (int i = 2;i<=n;i++)
{
for (int j = 1;j<i;j++)
{
char temp[5];
scanf("%s",&temp);
if (temp[0] != 'x')
mapp[i][j]=mapp[j][i]=atoi(temp);
}
}
dijkstra();
}
//freopen("in","r",stdin);
//scanf("%d",&T);
//printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
return 0;
}
题目