思路:用深搜遍历出所有可达路径,每找到一条新路径时,对最大救援人数和最短路径数进行更新。

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=;
int tu[N][N],city[N],vis[N];//tu存道路,city存各城市救援人数,vis为标记数组
int n,m,start,dis,path=,shortest=1e8,allpeople=;//path为最短路径数,allpeople为最大救援人数
void read()
{
memset(vis,,sizeof(vis));
fill(tu[],tu[]+N*N,);
cin>>n>>m>>start>>dis;
for (int i=;i<n;i++)
cin>>city[i];
int a,b,c;
for (int i=;i<m;i++)
{
cin>>a>>b>>c;
tu[a][b]+=c;//注意题目,是无向图!!
tu[b][a]+=c;
}
}
void dfs(int step,int now,int people)
{
people+=city[now];//要先加上该城市救援人数!
if (now==dis)
{
if (step<shortest)
{
shortest=step;
allpeople=people;
path=;
}
else if (step==shortest)//这里要用else if不能用if!!如果用if会在第一次更新时满足这两个if判断,导致path多加了一次!!
{
path++;
allpeople=max(allpeople,people);
}
return;
}
vis[now]=;
for (int i=;i<n;i++)
{
if (tu[now][i]>&&vis[i]==)
{
step+=tu[now][i];
dfs(step,i,people);
step-=tu[now][i];
}
}
vis[now]=;
}
int main()
{
// freopen("in.txt","r",stdin);
read();//输入函数
dfs(,start,);//深搜遍历所有路径
cout<<path<<" "<<allpeople<<endl; return ;
}

PAT (Advanced Level) Practice 1003 Emergency的更多相关文章

  1. PAT (Advanced Level) Practice 1003 Emergency 分数 25 迪杰斯特拉算法(dijkstra)

    As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...

  2. PAT (Advanced Level) Practise 1003 Emergency(SPFA+DFS)

    1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

  3. PAT (Advanced Level) Practice 1001-1005

    PAT (Advanced Level) Practice 1001-1005 PAT 计算机程序设计能力考试 甲级 练习题 题库:PTA拼题A官网 背景 这是浙大背景的一个计算机考试 刷刷题练练手 ...

  4. PAT (Advanced Level) Practice(更新中)

    Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性 ...

  5. PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...

  6. PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...

  7. PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642 题目描述: Being unique is so important to peo ...

  8. PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642 题目描述: To prepare for PAT, the judge someti ...

  9. PAT (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642 题目描述: Given any string of N (≥5) ...

随机推荐

  1. January 13 2017 Week 2 Friday

    Those who turn back never reach the summit. 回头的人永远也到不了顶峰. I always turned back on my life road, so i ...

  2. Entity Framework:代码优先

    一.代码优先Code First EF6支持Oracle ODT 12C Release 3 (net4.5) DataModel(类)-->生成数据库DB 或 存在的数据库DB-->生成 ...

  3. mysql之mof提权详解

    原理解读: Windows 管理规范 (WMI) 提供了以下三种方法编译到 WMI 存储库的托管对象格式 (MOF) 文件: 方法 1: 运行 MOF 文件指定为命令行参数将 Mofcomp.exe  ...

  4. Angular4 @HostBinding @HostListener

    host属性 @Component({ selector: 'jhi-project', templateUrl: './project.html', styleUrls: [], host: { ' ...

  5. eclipse 自动生成get/set方法

    Shift+Alt+S 会弹出一个对话框 选择Generate Getters and Setters

  6. 2018-2019-2 网络对抗技术 20165322 Exp4 恶意代码分析

    2018-2019-2 网络对抗技术 20165322 Exp4 恶意代码分析 目录 实验内容与步骤 系统运行监控 恶意软件分析 实验过程中遇到的问题 基础问题回答 实验总结与体会 实验内容与步骤 系 ...

  7. [HNOI2006]马步距离

    嘟嘟嘟 这题首先直接bfs可定过不了,因此可以先贪心缩小两个点的距离,直到达到某一个较小的范围(我用的是30),再bfs暴力求解. 首先我们求出这两个点的相对距离x, y,这样就相当于从(x, y) ...

  8. [Python 多线程] Condition (十)

    Condition常用于生产者.消费者模型,为了解决生产者消费者速度匹配问题. 构造方法Condition(lock=None),可以传入一个Lock或RLock对象,默认RLock. 方法: acq ...

  9. 【转】CopyOnWriteArrayList

    初识CopyOnWriteArrayList 第一次见到CopyOnWriteArrayList,是在研究JDBC的时候,每一个数据库的Driver都是维护在一个CopyOnWriteArrayLis ...

  10. 指纹协查统计sql

     select dic.name, NVL(zc.zc_djzs,0),NVL(zc.zc_shzs,0),NVL(zc.zc_bzzs,0), NVL(zt.zt_djzs,0),NVL(zt.zt ...