l这篇有空再补吧
l
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include<iostream> #include<cstdio> #include<string.h> #include<string> #include<math.h> #include<map> #define maxn 405 #define INF 0x3f3f3f3f using namespace std; typedef long long ll; int n,m,c,x; string a,b; map<int,string> ma; map<string,int> rma; int dr[maxn],vis[maxn],dis[maxn],path[maxn],city[maxn],pnum[maxn],kill[maxn],edge[maxn][maxn]; void dijkstra(int s) { memset(vis,0,sizeof(vis)); memset(pnum,0,sizeof(pnum)); memset(dis,INF,sizeof(dis)); memset(kill,0,sizeof(kill)); memset(city,0,sizeof(city)); dis[s]=0; pnum[s]=1; path[s]=-1; while(true) { //int u=-1,minn=INF; int u=-1; for(int i=0;i<n;i++) { if(!vis[i]&&(u==-1||dis[i]<dis[u])) u=i; } if(u==-1) break; vis[u]=1; for(int i=0;i<n;i++) { if(!vis[i]&&edge[u][i]) { if(dis[i]>dis[u]+edge[u][i]) { dis[i]=dis[u]+edge[u][i]; path[i]=u; kill[i]=kill[u]+dr[i]; city[i]=city[u]+1; pnum[i]=pnum[u]; } else if(dis[i]==dis[u]+edge[u][i]) { pnum[i]+=pnum[u]; if(city[i]<city[u]+1) { city[i]=city[u]+1; path[i]=u; kill[i]=kill[u]+dr[i]; } else if(city[i]==city[u]+1) { if(kill[i]<kill[u]+dr[i]) { kill[i]=kill[u]+dr[i]; path[i]=u; } } } } } } } void display(int x) { if(path[x]==-1) { cout<<ma[x]; return; } display(path[x]); cout<<"->"<<ma[x]; return; } int main() { int end; cin>>n>>m>>a>>b; ma[0]=a; rma[a]=0; dr[0]=0; for(int i=1;i<n;i++) { cin>>a>>dr[i]; ma[i]=a; rma[a]=i; if(a==b) end=i; } memset(edge,INF,sizeof(edge)); for(int i=0;i<m;i++) { cin>>a>>b>>c; int t1=rma[a]; int t2=rma[b]; edge[t1][t2]=edge[t2][t1]=c; } dijkstra(0); display(end); cout<<endl; cout<<pnum[end]<<" "<<dis[end]<<" "<<kill[end]<<endl; return 0; }