题意: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. STA之RC Corner再论

    Q:RC-Corner跟PVT怎么组合? A:通常的组合:   Q:通常说的ttcorner指的是啥? A:@孟时光 ttcorner是指管子在tt+RCtyp吧. Typesof corners W ...

  2. active Directory域服务安装配置

    1.在Windows功能启用 2.安装一直下一步即可, 添加用户 添加域管理员 将普通用户添加到Domain Admins里

  3. python专题知识追寻者对OS的理解

    一 前言 OS(operating system)直接对操作系统进行操作的接口,功能真是非常强大:允许知识追寻者简要概括一下整体模块 如果要对文件进行读写可以使用os.open()方法 如果要对文件路 ...

  4. IntelliJ IDEA 2017.3尚硅谷-----设置项目文件编码

    这也可以 R暂时显示 C转换

  5. IntelliJ IDEA 2017.3尚硅谷-----安装

    选择路径 安装目录 bin目录下的文件 启动文件 虚拟机的配置信息 -Xms128m 初始内存 -Xmx750m 最大内存-XX:ReservedCodeCacheSize=240m 可保留代码缓存的 ...

  6. python开发基础01-字符串操作方法汇总

    字符串 Python对字符串的处理内置了很多高效的函数,非常方便功能很强大. "hello world" 字符串七种常用功能: 连接和合并 + join 移除空白  strip 分 ...

  7. linx下跑多个tomcat

    1.修改server.xml文件 <Server port="8005" shutdown="SHUTDOWN"> <Connector po ...

  8. tomcat在win10系统中安装失败的问题,修改tomcat内存

    自己以前在其他系统上安装tomcat服务都没有问题,但是在win10系统上安装就经常出现问题,自己总结了一下安装步骤: 1.首先需要配置环境变量, CATALINA_HOME 2.修改service. ...

  9. 洛谷P1044栈(DP)

    题目背景 栈是计算机中经典的数据结构,简单的说,栈就是限制在一端进行插入删除操作的线性表. 栈有两种最重要的操作,即poppoppop(从栈顶弹出一个元素)和pushpushpush(将一个元素进栈) ...

  10. nginx配置访问密码,输入用户名和密码才能访问

    1. 安装 htpasswd 工具 yum install httpd-tools -y 设置用户名和密码,并把用户名.密码保存到指定文件中: [sandu@bogon conf]$ sudo mkd ...