PAT1003

#include<iostream>
#include<cstring>
#include<climits>
using namespace std;

int n, m, c1, c2;
//dis[i]从起点到i的最短路径,num[i]为长度,weight[i]为i城的救援小组人数,w[i]为到i城已经接到的救援人数,e[][]路径权重
int dis[500], num[500], weight[500], w[500], e[500][500]; bool visit[500] = {false}; const int MAX = 99999999; int main() { while(cin>>n>>m>>c1>>c2) { //input for(int i = 0; i < n; i++) cin>>weight[i]; int _s, _e, _w; fill(e[0], e[0] + 500 * 500, MAX); fill(dis, dis + 500, MAX); for(int i = 0; i < m; i++) { cin>>_s>>_e>>_w; e[_s][_e] = e[_e][_s] = _w; } dis[c1] = 0; num[c1] = 1; w[c1] = weight[c1];     
    
     //循环dis[0] ----> dis[max]
for(int i = 0; i < n; i++) { int _min = MAX, u = -1; for(int j = 0; j < n; j++) { if(!visit[j] && dis[j] < _min) { u = j; _min = dis[j]; } } if(u == -1) break; visit[u] = true; for(int v = 0; v < n; v++) { if(!visit[v]&& e[u][v] != MAX) {
            //最短路径长度
if(dis[u] + e[u][v] < dis[v]) { dis[v] = dis[u] + e[u][v]; num[v] = num[u]; w[v] = w[u] + weight[v]; } else if(dis[u] + e[u][v] == dis[v]) { num[v] = num[v] + num[u]; if(w[u] + weight[v] > w[v]) w[v] = w[u] + weight[v]; } } } } cout<<num[c2]<<" "<<w[c2]<<endl; } return -1; }

 

posted @ 2019-08-05 16:58  Stoves  阅读(112)  评论(0编辑  收藏  举报