#include <bits/stdc++.h>
using namespace std;
const int inf=1e9;
const int maxn=100;
int Map[maxn][maxn];
int vis[maxn];
int dis[maxn];
int n,m,v;
void dijstra()
{
int head,tail;
cout<<"起点景点:"<<" "<<"终点景点:";
cin>>head>>tail;
//cin>>tail;
memset(vis,0,sizeof(vis));
memset(dis,0,sizeof(dis));
for(int i=head;i<=tail;i++)
{
dis[i]=Map[head][i];
}
for(int i=1;i<=tail;i++)
{
int mi=9999;
for(int j=1;j<=tail;j++)
{
if(!vis[j]&&dis[j]<mi)
{
mi=dis[j];
v=j;
}
}
vis[v]=1;
for(int k=1;k<=n;k++)
{
if(!vis[k]&&dis[k]>dis[v]+Map[v][k])
{
dis[k]=dis[v]+Map[v][k];
}
}
}
cout<<"校园景点间的最短路径:"<<dis[tail]<<endl;
}
int main()
{
cout<<"校园有几个景点:";
while(scanf("%d",&n))
{
cout<<"景点之间有多少条路:";
scanf("%d",&m);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==j)
Map[i][j]=0;
else
Map[i][j]=inf;
}
}
for(int i=1;i<=m;i++)
{
int x,y,z;
cout<<"景点地点编号:"<<"景点地点编号:"<<"景点之间距离:";
cin>>x>>y>>z;
if(Map[x][y]>z)
{
Map[x][y]=z;
Map[y][x]=z;
}
}
dijstra();
}
}
using namespace std;
const int inf=1e9;
const int maxn=100;
int Map[maxn][maxn];
int vis[maxn];
int dis[maxn];
int n,m,v;
void dijstra()
{
int head,tail;
cout<<"起点景点:"<<" "<<"终点景点:";
cin>>head>>tail;
//cin>>tail;
memset(vis,0,sizeof(vis));
memset(dis,0,sizeof(dis));
for(int i=head;i<=tail;i++)
{
dis[i]=Map[head][i];
}
for(int i=1;i<=tail;i++)
{
int mi=9999;
for(int j=1;j<=tail;j++)
{
if(!vis[j]&&dis[j]<mi)
{
mi=dis[j];
v=j;
}
}
vis[v]=1;
for(int k=1;k<=n;k++)
{
if(!vis[k]&&dis[k]>dis[v]+Map[v][k])
{
dis[k]=dis[v]+Map[v][k];
}
}
}
cout<<"校园景点间的最短路径:"<<dis[tail]<<endl;
}
int main()
{
cout<<"校园有几个景点:";
while(scanf("%d",&n))
{
cout<<"景点之间有多少条路:";
scanf("%d",&m);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==j)
Map[i][j]=0;
else
Map[i][j]=inf;
}
}
for(int i=1;i<=m;i++)
{
int x,y,z;
cout<<"景点地点编号:"<<"景点地点编号:"<<"景点之间距离:";
cin>>x>>y>>z;
if(Map[x][y]>z)
{
Map[x][y]=z;
Map[y][x]=z;
}
}
dijstra();
}
}