Emergency
题意:有N个点,M条边,每个点有权值,问从起点到终点最短路的个数以及权值最大的最短路的权值。
分析:修改Dijstra模板。
#include<bits/stdc++.h>
using namespace std;
const int INT_INF = 0x3f3f3f3f;
const int MAXN = 500 + 10;
int weight[MAXN];
typedef long long LL;
struct Edge{
int from, to;
LL dist;
Edge(int f, int t, LL d):from(f), to(t), dist(d){}
};
struct HeapNode{
LL d;
int u;
HeapNode(LL dd, int uu):d(dd), u(uu){}
bool operator < (const HeapNode& rhs)const{
return d > rhs.d;
}
};
struct Dijkstra{
int n, m;
vector<Edge> edges;
vector<int> G[MAXN];
LL d[MAXN];
int num[MAXN];
int value[MAXN];
bool done[MAXN];
void init(int n){
this -> n = n;
for(int i = 0; i <= n; ++i) G[i].clear();
edges.clear();
}
void AddEdge(int from, int to, LL dist){
edges.push_back(Edge(from, to, dist));
m = edges.size();
G[from].push_back(m - 1);
}
void dijkstra(int s){
priority_queue<HeapNode> Q;
for(int i = 0; i <= n; ++i){
d[i] = 0x3f3f3f3f3f3f3f3f;
}
memset(done, false, sizeof done);
d[s] = 0;
num[s] = 1;
value[s] = weight[s];
Q.push(HeapNode(0, s));
while(!Q.empty()){
HeapNode x = Q.top();
Q.pop();
int u = x.u;
if(done[u]) continue;
done[u] = true;
for(int i = 0; i < G[u].size(); ++i){
Edge &e = edges[G[u][i]];
if(d[e.to] > d[u] + e.dist) {
d[e.to] = d[u] + e.dist;
num[e.to] = num[u];
value[e.to] = value[u] + weight[e.to];
Q.push(HeapNode(d[e.to], e.to));
}
else if(d[e.to] == d[u] + e.dist){
num[e.to] += num[u];
if(value[u] + weight[e.to] > value[e.to]){
value[e.to] = value[u] + weight[e.to];
}
}
}
}
}
}dij;
int main(){
int n, m, st, et;
scanf("%d%d%d%d", &n, &m, &st, &et);
for(int i = 0; i < n; ++i){
scanf("%d", &weight[i]);
}
dij.init(n);
int x, y;
LL l;
for(int i = 0; i < m; ++i){
scanf("%d%d%lld", &x, &y, &l);
dij.AddEdge(x, y, l);
dij.AddEdge(y, x, l);
}
dij.dijkstra(st);
printf("%d %d\n", dij.num[et], dij.value[et]);
return 0;
}
Emergency的更多相关文章
- 1003. Emergency (25)
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- Emergency(山东省第一届ACM省赛)
Emergency Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Kudo’s real name is not Kudo. H ...
- 1003. Emergency
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 ...
- C3P0连接池问题,APPARENT DEADLOCK!!! Creating emergency..... [问题点数:20分,结帖人lovekong]
采用c3p0连接池,每次调试程序,第一次访问时(Tomcat服务器重启后再访问)都会出现以下错误,然后连接库需要很长时间,最终是可以连上的,之后再访问就没问题了,请高手们会诊一下,希望能帮小弟解决此问 ...
- PAT 解题报告 1003. Emergency (25)
1003. Emergency (25) As an emergency rescue team leader of a city, you are given a special map of yo ...
- 解决:Android4.3锁屏界面Emergency calls only - China Unicom与EMERGENCY CALL语义重复
从图片中我们可以看到,这里在语义上有一定的重复,当然这是谷歌的原始设计.这个问题在博客上进行共享从表面上来看着实没有什么太大的意义,不过由于Android4.3在锁屏功能上比起老版本做了很大的改动,而 ...
- Active Session History (ASH) Performed An Emergency Flush Messages In The Alert Log
Active Session History (ASH) Performed An Emergency Flush Messages In The Alert Log (文档 ID 1385872.1 ...
- PAT 1003. Emergency (25)
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- CentOS7开机提示welcome to emergency mode!after logging in...
CentOS7.3昨天用的还好好的的,但是今天开机提示如下(如图提示): welcome to emergency mode!after logging in ,type "journalc ...
随机推荐
- C++11常用特性介绍——Lambda表达式
一.C++11采用配对的方括号[]来创建一个匿名函数并执行,如: #include <iostream> int main() { auto func = []{ std::cout &l ...
- knockout 简单使用
定义: var QcViewModel = function () { var self = this; self.name = ko.observable(); self.qty = ko.obse ...
- springboot搭建的web数据提交乱码
修改:application.yml或者application.properties文件 将 url: jdbc:mysql://127.0.0.1:3306/shiro 修改为: url: jdbc ...
- Keras下载的数据集以及预训练模型保存在哪里
Keras下载的数据集在以下目录中: root\\.keras\datasets Keras下载的预训练模型在以下目录中: root\\.keras\models 在win10系统来说,用户主目录是: ...
- k8spod的介绍
yaml介绍 apiVersion: v1 APIserver 的版本 kind: Pod 资源类型 metadata: 元数据定义 name: pod-demo 元数据资源名字 labels: 定义 ...
- npm安装包时报错:Error: EPERM: operation not permitted, rename
解决方法:先执行 npm cache clean -force在安装需要的包.
- Struts2学习(五)
表达式 1.表达式语言 ( Expression Language )2.表达式的本质: 就是 按照某种规则 书写的 字符串3.表达式的处理: 一定有一套程序 对 表达式 中的 字符串进行解析和处理 ...
- 记录5-如何在UltraEdit中编译和运行Java
1点击“高级”,再点击“工具配置” 2点击“插入”,在“菜单项”名称上输入“编译java程序”,在“命令行”里输入“javac %n%e”,在工作目录上填“%p”. 3切换到“输出”项,选择“输出到列 ...
- c++构造函数的初始化列表(翁恺c++公开课[13])
初始化列表形式: class Point { private: const float x,y; Point(float xa = 0.0, flato ya = 0.0):y(ya),x(xa) { ...
- HDU 5570:balls 期望。。。。。。。。。。。。。。。
balls Accepts: 19 Submissions: 55 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/655 ...