#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
#define INF 0xfffffff
int pri[1010][1010];//两个顶点之间距离
int dis[1010];//起点到该点的最短距离
int vis[1010];//标记数组
int n, m;
void dijkstra(int p)
{
memset(vis, 0, sizeof(vis));
vis[p] = 1;
for (int i = 1; i <= n; i++)
dis[i] = pri[p][i];
for (int i = 0; i<n; i++)
{
int M = INF, k = -1;
for (int j = 1; j <= n; j++)
{
if (!vis[j] && dis[j]<M)
M = dis[j], k = j;
}
if (k == -1)
return;
vis[k] = 1;
for (int j = 1; j <= n; j++)
if (!vis[j] && dis[j]>dis[k] + pri[k][j])
dis[j] = dis[k] + pri[k][j];
}
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
pri[i][j] = i == j ? 0 : INF;
for (int i = 1; i <= m; i++)
{
int a, b, c;
cin >> a >> b >> c;
pri[a][b] = pri[b][a] = c;
}
int ans = 0;
int maxl = INF;
for (int i = 1; i <= n; i++)
{
int s = 0;
dijkstra(i);
for (int j = 1; j <= n; j++)
{
s = max(s, dis[j]);
}
if (s < maxl)
{
maxl = s;
ans = i;
}
}
if (maxl == INF)
cout << 0 << endl;
else
cout << ans << ' ' << maxl << endl;
system("pause");
return 0;
}
07-图4 哈利·波特的考试
最新推荐文章于 2023-08-06 14:54:19 发布