PAT (Advanced Level) Practice 1003 Emergency
思路:用深搜遍历出所有可达路径,每找到一条新路径时,对最大救援人数和最短路径数进行更新。
#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的更多相关文章
- 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 ...
- PAT (Advanced Level) Practise 1003 Emergency(SPFA+DFS)
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- PAT (Advanced Level) Practice 1001-1005
PAT (Advanced Level) Practice 1001-1005 PAT 计算机程序设计能力考试 甲级 练习题 题库:PTA拼题A官网 背景 这是浙大背景的一个计算机考试 刷刷题练练手 ...
- PAT (Advanced Level) Practice(更新中)
Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性 ...
- PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642
PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...
- PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642
PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...
- 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 ...
- PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642
PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642 题目描述: To prepare for PAT, the judge someti ...
- 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) ...
随机推荐
- 沉淀再出发:关于IntelliJ IDEA使用的一些总结
沉淀再出发:关于IntelliJ IDEA使用的一些总结 一.前言 在使用IDEA的时候我们会发现,如果我们先写了一个类的名字,而没有导入这个类的出处,就会提示出错,但是不能自动加入,非常的苦恼,并且 ...
- January 02 2017 Week 1st Monday
A day is a miniature of eternity. 一天是永恒的缩影. My life is short, but I can make something eternal. What ...
- 2、Node.js 第一个应用
内容:三种变量申明方式,Node.js应用组成,第一个应用创建+代码 ################################################################# ...
- MySQL 触发器-更新字段时,status列会加一
需求:当更新列中的字段时,列中的status字段,就会+1 表结构 CREATE TABLE `test_1` ( `id` int(11) DEFAULT NULL, `name` varchar( ...
- 【[SDOI2011]拦截导弹】
这道题是真的蛇皮 方案数要开\(double\)真的蛇皮 首先\(dp\)是非常容易看出来的 设\(dp[i]\)表示以\(i\)结尾的最长子序列 显然转移方程为 \[dp[i]=max(dp[j]+ ...
- git命令将本地代码提交到github
git命令将本地代码提交到github 步骤: 第一步:进入到相应的文件夹,用git init命令,将该文件夹变成git可管理的仓库 git init 第二步:将项目添加到本地仓库 可以用git st ...
- use tool wget for windows download
1.什么是wget Wget是一个在网络上进行下载的简单而强大的自由软件,其本身也是GNU计划的一部分.它的名字是"World Wide Web"和"Get"的 ...
- ant design 修改tab样式
.ant-tabs-ink-bar{ background-color: transparent !important; } .ant-tabs-top .ant-tabs-ink-bar-anima ...
- CSS3中为什么要清除浮动以及三种清除浮动(float)的方法
方法一:添加新的元素 .应用 clear:both .clear{ clear:both; height: 0; height: 0; overflow:hidden; } 方法二:父级div定义 o ...
- Oracle输出数字1-10
,) from dual connect by level<