【PAT甲级】1003 Emergency (25 分)(SPFA,DFS)
题意: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)的更多相关文章
- PAT 甲级 1003. Emergency (25)
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- 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 ...
- PAT甲级1003. Emergency
PAT甲级1003. Emergency 题意: 作为一个城市的紧急救援队长,你将得到一个你所在国家的特别地图.该地图显示了几条分散的城市,连接着一些道路.每个城市的救援队数量和任何一对城市之间的每条 ...
- 图论 - PAT甲级 1003 Emergency C++
PAT甲级 1003 Emergency C++ As an emergency rescue team leader of a city, you are given a special map o ...
- 1003 Emergency (25分) 求最短路径的数量
1003 Emergency (25分) As an emergency rescue team leader of a city, you are given a special map of ...
- PAT 甲级 1078 Hashing (25 分)(简单,平方二次探测)
1078 Hashing (25 分) The task of this problem is simple: insert a sequence of distinct positive int ...
- PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)
1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...
- PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)
1032 Sharing (25 分) To store English words, one method is to use linked lists and store a word let ...
- PAT 甲级 1029 Median (25 分)(思维题,找两个队列的中位数,没想到)*
1029 Median (25 分) Given an increasing sequence S of N integers, the median is the number at the m ...
随机推荐
- jenkins发布.war包到本地tomcat
前提:保证jenkins构建打包成功 1.配置tomcat的用户名密码(此处tomcat为本地任意tomcat包,jenkins会通过Deploy war/ear to container配置的url ...
- python文件读取:遇见的错误及解决办法
问题一: TypeError: 'str' object is not callable 产生原因: 该错误TypeError: 'str' object is not callable字面上意思:就 ...
- linux nmon安装
系统版本红帽7.7: [root@hostuser1 nmon_permon]# cat /etc/redhat-release CentOS Linux release 7.7.1908 (Core ...
- bootstrap环境
<!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- jmeter的使用---JDBC
一.数据库连接配置JDBC Connection Configuration 二.执行sql语句select statement (1)query type类型介绍 select statement: ...
- 【安卓逆向】ARM常见汇编指令总结
跳转指令 B 无条件跳转 BL 带链接的无条件跳转 BX 带状态切换的无条件跳转 BLX 带链接和状态的无条件跳转 存储器与寄存器交互数据指令(核心) 存储器:主存和内存 寄存器中放的数据:可以是字符 ...
- vue中移动端调取本地的复制的文本
_this.$vux.confirm.show({ title: '复制分享链接', content: ‘分享的内容’, onConfi ...
- CSS学习(5)更多的选择器
1.通配符选择器 * 表示选中所有元素 *{color:red;} 2.属性选择器 根据属性名和属性值选中元素 https://developer.mozilla.org/zh-CN/docs/We ...
- nodejs的req取参req.body,req.params,req.query
1/req.query: Get:/domo?name=ximiximi&blog=https://home.cnblogs.com/u/ximiximi-blog/ app.get('/do ...
- Win10-IIS注册asp 此操作系统版本不支持此选项 错误解决方法
现象再现: 今日在Win10上面ASP.NET网站突然不能跑了, 过程再现: 根据资料提示重新注册ASPNET_IIS.exe -i 直接提示: C:\WINDOWS\system32>c:\w ...