1、比较函数里要考虑所有维数的优先级
2、每个节点出队列一次，防止相同最短路数量重复计数

``````#include<cstdio>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
using namespace std;

const int N=200+5;

struct Edge
{
int v,w,next;
}edge[N*N];

struct Node
{
int u,dis,d,hap;
bool operator<(const Node& p)const
{
if(dis!=p.dis) return dis>p.dis;
if(hap!=p.hap) return hap<p.hap;
return d>p.d;
}
};

int a[N];
int dis[N],d[N],hap[N],num[N],pre[N],vis[N];
map<string,int> mp;
map<int,string> rmp;

{
};

void dijs(int s)
{
memset(dis,0x3f,sizeof(dis));
priority_queue<Node> q;
q.push({s,0,0,0});
dis[s]=0,d[s]=0,hap[s]=0,num[s]=1;
while(!q.empty())
{
Node u=q.top();
q.pop();
if(vis[u.u]) continue;
vis[u.u]=1;
{
int v=edge[i].v,w=edge[i].w;
if(dis[u.u]+w<dis[v])
{
dis[v]=dis[u.u]+w;
pre[v]=u.u;
num[v]=num[u.u];
hap[v]=hap[u.u]+a[v];
d[v]=d[u.u]+1;
q.push({v,dis[v],d[v],hap[v]});
}
else if(dis[u.u]+w==dis[v])
{
num[v]+=num[u.u];
if(hap[u.u]+a[v]>hap[v])
{
pre[v]=u.u;
hap[v]=hap[u.u]+a[v];
d[v]=d[u.u]+1;
q.push({v,dis[v],d[v],hap[v]});
}
else if(hap[u.u]+a[v]==hap[v])
{
if(d[u.u]+1<d[v])
{
pre[v]=u.u;
d[v]=d[u.u]+1;
q.push({v,dis[v],d[v],hap[v]});
}
}
}
}
}
}

void dfs(int u)
{
if(!pre[u])
{
cout<<rmp[u];
return;
}
dfs(pre[u]);
cout<<"->"<<rmp[u];
}

int main()
{
int n,k;
string u;
cin>>n>>k>>u;
int cnt=0;
edgetot=0;
mp[u]=++cnt,rmp[cnt]=u;
for(int i=1;i<=n-1;i++)
{
cin>>u;
mp[u]=++cnt,rmp[cnt]=u;
cin>>a[mp[u]];
}
while(k--)
{
string u,v;
int w;
cin>>u>>v>>w;
}
dijs(1);
int ed=mp["ROM"];
printf("%d %d %d %d\n",num[ed],dis[ed],hap[ed],hap[ed]/d[ed]);
dfs(ed);
cout<<endl;
return 0;
}
``````