1003 Emergency (25 分)(迪杰斯特拉)

经典题目

#include"bits/stdc++.h"
using namespace std;
int diffway[1000];
int table[1000][1000];
int doctor[1000];
int dis[1000];
int vis[1000];
int ansdoctor[1000];
int main(){
	memset(table, 0x3f, 4000000);
	memset(dis, 0x3f, 4000);
	memset(vis, 0, 4000);
	memset(ansdoctor, 0, 4000);
	int n, roadn, from, dest;
	cin >> n >> roadn >> from >> dest;
	for(int i = 0; i < n; ++i) cin >> doctor[i];
	for(int i = 0; i < roadn; ++i){
		int a, b, way;
		cin >> a >> b >> way;
		table[a][b] = table[b][a] = way;
	}
	dis[from] = 0;
	diffway[from] = 1;
	ansdoctor[from] = doctor[from];
	while(1){
		int p = -1;
		int mindis = 0x3f3f3f3f;
		for(int i = 0; i < n; ++i){
			if(dis[i] < mindis && !vis[i]){
				mindis = dis[i];
				p = i;
			}
		}
		if(-1 == p) break;
		vis[p] = 1;
		for(int i = 0; i < n; ++i){
			if(0x3f3f3f3f != table[p][i] && dis[p] + table[p][i] <= dis[i]){
				if(dis[p] + table[p][i] == dis[i]){
					diffway[i] += diffway[p];
					ansdoctor[i] = max(ansdoctor[i], ansdoctor[p] + doctor[i]);
				}
				else{
					dis[i] = dis[p] + table[p][i];
					diffway[i] = diffway[p];
					ansdoctor[i] = ansdoctor[p] + doctor[i];
				}
			}
		}
	}
	cout << diffway[dest] << " " << ansdoctor[dest];
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值