题意:n个点,m条双向边,每条边给出通过用时,每个点给出点上的人数,给出起点终点,求不同的最短路的数量以及最短路上最多能通过多少人。(N<=500)

AAAAAccepted code:

 #include<bits/stdc++.h>
using namespace std;
int n,m;
int s,t;
int a[];
vector<pair<int,int> >adj[];
vector<int>pre[];
vector<int>tmp_path;
int ans=;
int d[];
bool inq[];
int sum=;
void SPFA(){
queue<int>q;
for(int i=;i<n;++i)
d[i]=1e9;
d[s]=;
q.push(s);
inq[s]=;
while(!q.empty()){
int u=q.front();
q.pop();
inq[u]=;
for(int i=;i<adj[u].size();++i){
int v=adj[u][i].first;
int l=adj[u][i].second;
if(d[u]+l<d[v]){
d[v]=d[u]+l;
pre[v].clear();
pre[v].push_back(u);
if(!inq[v]){
q.push(v);
inq[v]=;
}
}
else if(d[u]+l==d[v])
pre[v].push_back(u);
}
}
}
void DFS(int x){
if(x==s){
int tmp=;
for(int i=tmp_path.size()-;i>=;--i){
int u=tmp_path[i];
tmp+=a[u];
}
if(tmp>ans)
ans=tmp;
}
else
sum+=pre[x].size()-;
tmp_path.push_back(x);
for(int i=;i<pre[x].size();++i)
DFS(pre[x][i]);
tmp_path.pop_back();
}
int main(){
cin>>n>>m>>s>>t;
for(int i=;i<n;++i)
cin>>a[i];
for(int i=;i<m;++i){
int x,y,w;
cin>>x>>y>>w;
adj[x].push_back({y,w});
adj[y].push_back({x,w});
}
SPFA();
DFS(t);
cout<<sum<<" "<<ans+a[s];
return ;
}

【PAT甲级】1003 Emergency (25 分)(SPFA,DFS)的更多相关文章

  1. PAT 甲级 1003. Emergency (25)

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

  2. PAT 甲级1003 Emergency (25)(25 分)(Dikjstra,也可以自己到自己!)

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

  3. PAT甲级1003. Emergency

    PAT甲级1003. Emergency 题意: 作为一个城市的紧急救援队长,你将得到一个你所在国家的特别地图.该地图显示了几条分散的城市,连接着一些道路.每个城市的救援队数量和任何一对城市之间的每条 ...

  4. 图论 - PAT甲级 1003 Emergency C++

    PAT甲级 1003 Emergency C++ As an emergency rescue team leader of a city, you are given a special map o ...

  5. 1003 Emergency (25分) 求最短路径的数量

    1003 Emergency (25分)   As an emergency rescue team leader of a city, you are given a special map of ...

  6. PAT 甲级 1078 Hashing (25 分)(简单,平方二次探测)

    1078 Hashing (25 分)   The task of this problem is simple: insert a sequence of distinct positive int ...

  7. PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)

    1070 Mooncake (25 分)   Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...

  8. PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)

    1032 Sharing (25 分)   To store English words, one method is to use linked lists and store a word let ...

  9. PAT 甲级 1029 Median (25 分)(思维题,找两个队列的中位数,没想到)*

    1029 Median (25 分)   Given an increasing sequence S of N integers, the median is the number at the m ...

随机推荐

  1. qt5.9.0 msvc2015优雅的崩溃:dumpfile

    交给客户的软件奔溃了怎么办? 我们不能再客户电脑上安装vs,也不想傻傻的用log来猜测出错的地方. 利用Dbghelp可以解决这一问题. 首先是vs生成release版本的时候需要同时生成pdb文件, ...

  2. Linux中内容查看命令"大PK"

    众所周知linux中命令cat.more.less均可用来查看文件内容,当然还有我们"非主流"的vim以及使用较少的head.tail.tac. 下面我将介绍各种命令的用法及对比. ...

  3. Pandas数据结构(一)——Pandas Series

    Pandas 是 Python 中基于Numpy构建的数据操纵和分析软件包,包含使数据分析工作变得快速简洁的高级数据结构和操作工具.通过Pandas Series 和 Pandas DataFrame ...

  4. 一些 NuGet 程序包是使用不同于当前目标框架的目标框架安装的,可能需要重新安装

    如果 NuGet 检测到包受到重定向或升级项目的影响,它会将 packages.config 中的 requireReinstallation="true" 属性添加到所有受影响的 ...

  5. Linux - 命令 - 查找命令总结

    关于查找文件的几个命令 一.find命令 find是最常用也是最强大的查找命令,可以查找任何类型的文件 find命令的一般格式: find <指定目录><指定条件><指定 ...

  6. python中写入txt文件需要换行,以及\r 和\n

    在Python中,用open()函数打开一个txt文件,写入一行数据之后需要一个换行 如果直接用 f.write(’\n’)只会在后面打印一个字符串’\n’,而不是换行’需要用 f.write(’\r ...

  7. 南京邮电大学网络攻防平台(NCTF)-MD5-Writeup

    南京邮电大学网络攻防平台-MD5-Writeup 题干如下: 分析: 遍历 TASC?O3RJMV?WDJKX?ZM(?替换为其他),找到md5为e9032???da???08????911513?0 ...

  8. 获取目标字符串在字符串中第N次出现的位置

    /** * 获取目标字符串在字符串中第N次出现的位置 * @file name * @author xiehongwei * @date 2017-8-2 下午3:29:09 * @param sou ...

  9. angular iframe 加载失效解决办法已经自适应高度

    <iframe frameborder="0" id="iframe1"></iframe> $('#iframe1').attr('s ...

  10. ARM架构Linux环境安装python2.7.9

    1.下载python # wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz 2.解压.编译安装 # tar -zxvf Pyt ...