1003. Emergency (25)-PAT

本文介绍了一种紧急救援场景下的最短路径算法实现。通过给定的城市地图信息,包括城市间道路长度及各城市救援队伍数量,算法能够找出从当前城市到目标城市的最短路径及其能集结的最大救援队伍数量。

1003. Emergency (25)

时间限制
400 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked on the map. When there is an emergency call to you from some other city, your job is to lead your men to the place as quickly as possible, and at the mean time, call up as many hands on the way as possible.

Input

Each input file contains one test case. For each test case, the first line contains 4 positive integers: N (<= 500) - the number of cities (and the cities are numbered from 0 to N-1), M - the number of roads, C1 and C2 - the cities that you are currently in and that you must save, respectively. The next line contains N integers, where the i-th integer is the number of rescue teams in the i-th city. Then M lines follow, each describes a road with three integers c1, c2 and L, which are the pair of cities connected by a road and the length of that road, respectively. It is guaranteed that there exists at least one path from C1 to C2.

Output

For each test case, print in one line two numbers: the number of different shortest paths between C1 and C2, and the maximum amount of rescue teams you can possibly gather.
All the numbers in a line must be separated by exactly one space, and there is no extra space allowed at the end of a line.

Sample Input
5 6 0 2
1 2 1 5 3
0 1 1
0 2 2
0 3 1
1 2 1
2 4 1
3 4 1
Sample Output
2 4
迪杰特拉斯最短路径
#include<iostream>
#define max(a,b) ((a)>(b)?(a):(b))
using namespace std;
#define N 1000
int mapt[N][N];
int dist[N];
int visit[N];
int team[N];
int total[N];
int num_path[N];
#define  maxnum 0xfffffff
void  emergency(int n,int s)
{
    int i,j,k,preteams,u;
    for(i=0;i<n;i++){
        visit[i]=0;
		dist[i]=maxnum;
        total[i]=team[i];
		dist[i]=mapt[s][i];
    }
	dist[s]=0;
	total[s]=team[s];
	preteams=total[s];
    visit[s]=1;
    for(i=0;i<n;i++)
	{
		int tmp=maxnum;
		for(j=0;j<n;j++){
			if(visit[j]==0&&dist[j]<tmp)
			{
				tmp=dist[j];
				u=j;
			}
		}
		visit[u]=1;
		for(j=0;j<n;j++){
			if(visit[j]==0&&mapt[u][j]!=maxnum){
				if(dist[j]>dist[u]+mapt[u][j])
				{   
					dist[j]=dist[u]+mapt[u][j];
					total[j]=total[u]+team[j];
					num_path[j]=num_path[u];
				}
			   else if(dist[j]==dist[u]+mapt[u][j])
				{
					total[j]=max(total[j],total[u]+team[j]);
					if(mapt[s][u]!=0)
						num_path[j]+=num_path[u];
				}
			}

		}
    }
}
int main()
{
    int i,j,k;
	int n,c1,c2;
	long m;
    cin>>n;
    cin>>m;
    cin>>c1;
    cin>>c2;
    for(i=0;i<n;i++){
        for(j=0;j<n;j++)
        {
            mapt[i][j]=maxnum;
        }
		mapt[i][i]=0;
	}
    for(i=0;i<n;i++){
       cin>> team[i];
	   num_path[i]=1;
    }
    for(k=0;k<m;k++){
        cin>>i;
        cin>>j;
        cin>>mapt[i][j];
        mapt[j][i]=mapt[i][j];
    }
    emergency(n,c1);
	if(c1!=c2){
		total[c2]+=total[c1];
	}
    cout<<num_path[c2]<<" "<<total[c2]<<endl;
    return 0;

}


1panel.service bluetooth.target.wants clamav-daemon.service.d cloud-final.service.wants cloud-init.target.wants dbus-fi.w1.wpa_supplicant1.service dbus-org.bluez.service dbus-org.freedesktop.Avahi.service dbus-org.freedesktop.ModemManager1.service dbus-org.freedesktop.nm-dispatcher.service dbus-org.freedesktop.oom1.service dbus-org.freedesktop.resolve1.service dbus-org.freedesktop.thermald.service dbus-org.freedesktop.timesync1.service display-manager.service display-manager.service.wants docker.service emergency.target.wants final.target.wants getty.target.wants graphical.target.wants hibernate.target.wants hybrid-sleep.target.wants multi-user.target.wants network-online.target.wants nvidia-cdi-refresh.path nvidia-cdi-refresh.service oem-config.service.wants ollama.service paths.target.wants printer.target.wants rescue.target.wants sleep.target.wants snap-bare-5.mount snap.canonical-livepatch.canonical-livepatchd.service 'snap-canonical\x2dlivepatch-364.mount' 'snap-canonical\x2dlivepatch-372.mount' snap-clion-401.mount snap-code-214.mount snap-core-17247.mount snap-core20-2682.mount snap-core22-2139.mount snap-core22-2163.mount snap-core24-1196.mount snap-core24-1225.mount snap-cups-1127.mount snap-cups-1130.mount snap.cups.cups-browsed.service snap.cups.cupsd.service snap-curl-2351.mount snap-curl-2369.mount snapd.mounts.target.wants snap-firefox-7355.mount snap-firefox-7423.mount 'snap-firmware\x2dupdater-210.mount' 'snap-firmware\x2dupdater-216.mount' snap-freecad-1248.mount snap-freecad-1634.mount 'snap-gaming\x2dgraphics\x2dcore22-184.mount' 'snap-gaming\x2dgraphics\x2dcore24-13.mount' 'snap-gnome\x2d42\x2d2204-202.mount' 'snap-gnome\x2d42\x2d2204-226.mount' 'snap-gtk\x2dcommon\x2dthemes-1535.mount' 'snap-kf5\x2d5\x2d108\x2dqt\x2d5\x2d15\x2d10\x2dcore22-5.mount' 'snap-kf5\x2dcore22-3.mount' snap-snapd-25202.mount snap-snapd-25577.mount 'snap-snapd\x2ddesktop\x2dintegration-253.mount' 'snap-snapd\x2ddesktop\x2dintegration-315.mount' 'snap-snap\x2dstore-1173.mount' 'snap-snap\x2dstore-1270.mount' snap-steam-218.mount snap-steam-231.mount sockets.target.wants sshd-keygen@.service.d sshd.service ssh.service.requires sssd.service.wants suspend.target.wants suspend-then-hibernate.target.wants sysinit.target.wants syslog.service sysstat.service.wants systemd-hibernate.service.wants systemd-suspend.service.wants systemd-suspend-then-hibernate.service.wants timers.target.wants todeskd.service vncserver.service 帮我分析一下有哪些不必要
最新发布
12-07
要确定 `1panel.service`、`bluetooth.target.wants`、`clamav - daemon.service.d` 等服务和挂载项中哪些是不必要的,需要结合具体的使用场景和系统需求来分析: ### `1panel.service` `1panel.service` 通常是 1Panel 面板的服务。1Panel 是一款开源的 Linux 服务器运维管理面板,如果系统中不需要使用该面板来管理服务器,那么 `1panel.service` 就是不必要的。可以通过以下命令停止并禁用该服务: ```bash sudo systemctl stop 1panel.service sudo systemctl disable 1panel.service ``` ### `bluetooth.target.wants` `bluetooth.target.wants` 是蓝牙服务相关的目标依赖项目录。如果系统所在的设备没有蓝牙硬件,或者根本不需要使用蓝牙功能,那么与蓝牙相关的服务和依赖项就是不必要的。可以通过以下命令停止并禁用蓝牙服务: ```bash sudo systemctl stop bluetooth.service sudo systemctl disable bluetooth.service ``` ### `clamav - daemon.service.d` `clamav - daemon.service.d` 是 ClamAV 杀毒软件守护进程的配置目录。如果系统不需要进行病毒扫描,或者有其他的杀毒软件替代,那么 ClamAV 相关的服务就是不必要的。可以通过以下命令停止并禁用 ClamAV 守护进程服务: ```bash sudo systemctl stop clamav-daemon.service sudo systemctl disable clamav-daemon.service ``` ### 通用分析方法 还可以通过以下通用步骤进一步分析系统中不必要的服务和挂载项: 1. **查看服务状态**:使用 `systemctl list - unit - files` 命令列出所有服务单元文件的状态,找出已启用但当前不需要的服务。 2. **查看服务依赖关系**:使用 `systemctl list - dependencies` 命令查看某个服务的依赖关系,确保在停用服务时不会影响其他必要的功能。 3. **查看挂载项**:使用 `df -h` 和 `mount` 命令查看当前的挂载项,判断哪些挂载的文件系统是不必要的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值