题意:有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的更多相关文章

  1. 1003. Emergency (25)

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

  2. Emergency(山东省第一届ACM省赛)

    Emergency Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Kudo’s real name is not Kudo. H ...

  3. 1003. Emergency

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

  4. PAT (Advanced Level) Practise 1003 Emergency(SPFA+DFS)

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

  5. C3P0连接池问题,APPARENT DEADLOCK!!! Creating emergency..... [问题点数:20分,结帖人lovekong]

    采用c3p0连接池,每次调试程序,第一次访问时(Tomcat服务器重启后再访问)都会出现以下错误,然后连接库需要很长时间,最终是可以连上的,之后再访问就没问题了,请高手们会诊一下,希望能帮小弟解决此问 ...

  6. PAT 解题报告 1003. Emergency (25)

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

  7. 解决:Android4.3锁屏界面Emergency calls only - China Unicom与EMERGENCY CALL语义重复

    从图片中我们可以看到,这里在语义上有一定的重复,当然这是谷歌的原始设计.这个问题在博客上进行共享从表面上来看着实没有什么太大的意义,不过由于Android4.3在锁屏功能上比起老版本做了很大的改动,而 ...

  8. 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 ...

  9. PAT 1003. Emergency (25)

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

  10. CentOS7开机提示welcome to emergency mode!after logging in...

    CentOS7.3昨天用的还好好的的,但是今天开机提示如下(如图提示): welcome to emergency mode!after logging in ,type "journalc ...

随机推荐

  1. Bcrypt加密算法简介

    用户表的密码通常使用MD5等不可逆算法加密后存储,为防止彩虹表破解更会先使用一个特定的字符串(如域名)加密,然后再使用一个随机的salt(盐值)加密. 特定字符串是程序代码中固定的,salt是每个密码 ...

  2. 了解Web的相关知识

    一.WWW基础 WWW(world wide web, 万维网)是Internet上基于客户端/服务器体系结构的分布式多平台的超文本超媒体信息服务系统.它利用超文本(hypertext).超媒体(hy ...

  3. null值可以赋给引用变量,不能给基本类型

    下面正确的写法是? cbyte i=128 boolean i=null long i=0xfffL double i=0.9239d null表示没有地址:null可以赋值给引用变量,不能将null ...

  4. 无线渗透之ettercap

    无线渗透之ettercap ettercap命令查看 # ettercap -h Usage: ettercap [OPTIONS] [TARGET1] [TARGET2] TARGET is in ...

  5. Netsparker破解版5.3 Netsparker Enterprise 5.3.0.24388[cracked]

    Netsparker破解版5.3 Netsparker Enterprise 5.3.0.24388[cracked]该版本更新时间为2019年7月8日下载地址:1 https://www.dr-fa ...

  6. 如何往gitlab/github上游贡献代码

    Git 是一个开源的分布式版本控制系统,它能够记录每一次改动. 一些概念 仓库:git 中以仓库为单位:每个项目对应一个仓库,如 /eayuntest/Rally./eayuntest/stack 是 ...

  7. while语句及批量创建用户!

    1.while 循环语句的作用:重复测试某个条件,只要条件成立则反复执行2.while 语句结构while 条件测试操作do命令序列done ============================= ...

  8. get your sqlserver database back by using EMC NW NMM

    Dear all Yes ~ We can backup our sqlserver by EMC NW NMM. That is true and NW is a very very powerfu ...

  9. 学习Flutter应用开发有用的代码/库/专有技术列表

    当我开始使用Flutter开发该应用程序时,我开始担心:“最好的书写方式是什么?”以及“放置它的效果如何?”在这种情况下,您将需要学习和参考GitHub发布的代码和应用程​​序. 因此,我收集了似乎对 ...

  10. 【Java】变量命名规范

    Java是一种区分字母的大小写的语言,所以我们在定义变量名的时候应该注意区分大小写的使用和一些规范,接下来我们简单的来讲讲Java语言中包.类.变量等的命名规范. (一)Package(包)的命名 P ...