题意: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. PTPX-功耗分析总结

    使用PrimeTime PX进行功耗分析有两种:一种是平均功耗的分析Averaged power analysis,一种是Time-based power analysis.   电路的功耗主要有两种 ...

  2. poj 2195 Going Home(最小费用流)

    题目链接:http://poj.org/problem?id=2195 题目大意是给一张网格,网格中m代表人,h代表房子,网格中的房子和人数量相等,人可以向上向下走,每走1步花费加1,每个房子只能住一 ...

  3. php商城数据库的设计 之无限分类

    商品分类,使用无限分类 即: -------如何创建数据表 pid---父级分类id,如果是顶级分类则为0 path---1,用户分类的排序 . 排序示例: 实现逻辑:获取type表的所有分类,ord ...

  4. 题解【Codeforces1186A】 Vus the Cossack and a Contest

    这题是入门难度的题目吧-- 根据题意可以得出,只有当\(m\)和\(k\)都大于等于\(n\)时,\(Vus\)才可以实现他的计划. 因此,我们不难得出以下\(AC\)代码: #include < ...

  5. MySQL表的操作02

    [1]设置非空约束(NOT NULL ,NK)--->>>目的是f防止某些字段中的内容为空 CREATE TABLE +table_name ( 属性名   数据类型   NOT N ...

  6. 每天进步一点点------基础实验_12_有限状态机 :Moore型序列检测器

    /********************************************************************************* * Company : * Eng ...

  7. 粪发涂墙-tomcat

    tomcat 的 JAVA_OPTS 分析设置 快乐生活你我 2019-08-12 06:07:00 JAVA_OPTS ,顾名思义,是用来设置JVM相关运行参数的变量. 1.JVM:JAVA_OPT ...

  8. Python3问题TypeError: object() takes no parameters

    1. Python中关键字变量和特殊函数,都是以__xxx__来表示的 初学Python的朋友,需要注意其中变量名中前后是有两个下划线(_)的,如果不注意,调用内部关键字变量和特殊函数时,将会出现错误 ...

  9. C++ explicit的作用

    explicit作用: 在C++中,explicit关键字用来修饰类的构造函数,被修饰的构造函数的类,不能发生相应的隐式类型转换,只能以显示的方式进行类型转换. explicit使用注意事项: * e ...

  10. Robot Framework高级

    一.Web自动化测试 二.C/S自动化测试 三.数据库自动化测试 四.接口自动化测试 五.RF内置测试库 六.持续集成内置测试库 七.移动自动化测试 八.自定义RF