#include <iostream>
#include <climits>
using namespace std;
const int MAX=501;
int N, M, C1, C2;
int visited[MAX],map[MAX][MAX],cityTeam[MAX];
int minDistance=INT_MAX;
int numberRoad,maxTeams;
void dfs(int startCity,int endCity,int sumDistance,int sumTeam){
if(startCity==endCity){
if(sumDistance<minDistance){
numberRoad=1;
minDistance=sumDistance;
maxTeams=sumTeam;
}else if(sumDistance==minDistance){
numberRoad++;
if(sumTeam>maxTeams){
maxTeams=sumTeam;
}
}
return;
}
if(sumDistance>minDistance) return;
for(int i=0;i<N;i++){
if(visited[i]==0&&map[startCity][i]<INT_MAX){
visited[i]=1;
dfs(i,endCity,sumDistance+map[startCity][i],sumTeam+cityTeam[i]);
visited[i]=0;
}
}
}
int main(){
cin>>N>>M>>C1>>C2;
for(int i=0;i<N;i++){
cin>>cityTeam[i];
visited[i]=0;
for(int j=0;j<N;j++){
map[i][j]=INT_MAX;
}
}
int city1,city2,distance;
for(int i=0;i<M;i++){
cin>>city1>>city2>>distance;
map[city1][city2]=distance;
map[city2][city1]=map[city1][city2];
}
dfs(C1,C2,0,cityTeam[C1]);
cout<<numberRoad<<" "<<maxTeams;
}
PAT甲级1003
最新推荐文章于 2019-10-11 20:51:54 发布