#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<bits/stdc++.h>
//#define int long long
#define PII pair<int,int>
using namespace std;
const int N=550;
int n,m,s,d;
vector<PII> h[N];
int dist[N],pre[N],save[N],sum[N],num[N];
bool st[N];
void dijkstra(){
memset(dist,0x3f,sizeof dist);
pre[s]=-1;
priority_queue<PII,vector<PII>,greater<PII>> heap;
heap.push({0,s});
dist[s]=0;
sum[s]=save[s];
num[s]=1;
while(heap.size()){
auto t=heap.top();
heap.pop();
int v=t.second, distance=t.first;
if(st[v]) continue;
st[v]=true;
for(auto u:h[v]){
int a=u.first,b=u.second;
if(dist[a]>distance+b){
num[a]=num[v];
dist[a]=distance+b;
sum[a]=sum[v]+save[a];
pre[a]=v;
heap.push({dist[a],a});
}else if(dist[a]==distance+b){
num[a]+=num[v];
if(sum[a]<sum[v]+save[a]){
sum[a]=sum[v]+save[a];
pre[a]=v;
heap.push({dist[a],a});
}
}
}
}
}
signed main(){
cin>>n>>m>>s>>d;
for(int i=0;i<n;i++) cin>>save[i];
for(int i=0;i<m;i++){
int a,b,c;
cin>>a>>b>>c;
h[a].push_back({b,c});
h[b].push_back({a,c});
}
dijkstra();
vector<int> path;
int p=d;
while(p!=-1){
path.push_back(p);
p=pre[p];
}
reverse(path.begin(),path.end());
cout<<num[d]<<" "<<sum[d]<<endl;
for(int i=0;i<path.size();i++){
if(i) cout<<" "<<path[i];
else cout<<path[i];
}
return 0;
}
L2-001 紧急救援
于 2024-03-14 21:27:06 首次发布