这个程序抄来的。
#include <iostream>#include <vector>
using namespace std;
class CA
{
public:
enum{N=500,INF=0x6FFFFFFF};
void run();
void getshortestlen();
void getmaxhands(int k,int curhands);
private:
int n,m,sv,dv;
int hands[N];
int dist[N][N];
int shortestlen,shortestpathnum,maxhands;
vector<int> posipath[N];
};
void CA::getmaxhands(int k,int curhands)
{
if(k==sv)
{
shortestpathnum++;
if(curhands+hands[k]>maxhands) maxhands=curhands+hands[k];
}
int i;
for(i=0;i<posipath[k].size();i++)
{
getmaxhands(posipath[k][i],curhands+hands[k]);
}
}
void CA::getshortestlen()
{
shortestlen=-1;
bool visited[N];
int d[N];
fill_n(visited,n,false);
int i;
for(i=0;i<n;i++) d[i]=dist[sv][i];
d[sv]=0;
while(1)
{
int k=-1;
for(i=0;i<n;i++)
{
if(visited[i]) continue;
if(k==-1||d[i]<d[k]) k=i;
}
if(k==-1) break;
if(k==dv)
{
shortestlen=d[k];
break;
}
visited[k]=true;
for(i=0;i<n;i++)
{
if(visited[i]) continue;
if(d[i]>d[k]+dist[k][i])
{
d[i]=d[k]+dist[k][i];
posipath[i].clear();
posipath[i].push_back(k);
}
else if(d[i]==d[k]+dist[k][i])
{
posipath[i].push_back(k);
}
}
}
}
void CA::run()
{
shortestpathnum=0;
maxhands=0;
int i,v1,v2,w;
cin>>n>>m>>sv>>dv;
for(i=0;i<n;i++) cin>>hands[i];
fill_n((int*)dist,N*N,INF);
for(i=0;i<m;i++)
{
cin>>v1>>v2>>w;
dist[v1][v2]=w;
dist[v2][v1]=w;
}
getshortestlen();
getmaxhands(dv,0);
printf("%d %d\n",shortestpathnum,maxhands);
}
int main()
{
//freopen("test.in","r",stdin);
CA *a=new CA;
a->run();
return 0;
}