题意:有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. javaweb项目中web.xml配置文件的/和/*的区别

    1.拦截"/",可以实现现在很流行的REST风格.很多互联网类型的应用很喜欢这种风格的URL.为了实现REST风格,拦截了所有的请求.同时对*.js,*.jpg等静态文件的访问也就 ...

  2. OS(操作系统)结构

    1.整体式: 模块设计(独立的) 调用自由 用全局变量来通信 缺点:信息不安全,维护更新比较难 2.层次结构(典型的如TCP/IP协议): 所有的模块排成若干层,相邻的互相依赖调用 按调用次序来安排 ...

  3. 操作系统OS,Python - 有了GIL为什么还要threading.Lock()?

    参考: https://stackoverflow.com/questions/49859287/what-is-the-need-of-threading-lock-when-cpython-has ...

  4. Faster-RCNN Pytorch实现的minibatch包装

    实际上faster-rcnn对于输入的图片是有resize操作的,在resize的图片基础上提取feature map,而后generate一定数量的RoI. 我想首先去掉这个resize的操作,对每 ...

  5. Struts2报错异常Method "setUser" failed for object com.mikey.action.ConverterAction@dd34285

    在写类型转换的时候发现报错 异常信息 ognl.MethodFailedException: Method "setUser" failed for object com.mike ...

  6. 解决安装PyMySQL一直停在Building wheels for collected package:cryptography, cffi, pycparser的问题

    我的运行环境为: 硬件:树莓派3b 系统:ubuntu_meta_16.04.2 因为项目需要,我在树莓派上搭建了基于python编程的Django的web框架,需要从MySQL中读取树莓派以及传感器 ...

  7. 吴裕雄--天生自然PythonDjangoWeb企业开发:框架基础和技术选型

    简单的Web Server import socket eol1 = b'\n\n' eol2 = b'\n\r\n' body = '''Hello,world!<h1>tszrwyx& ...

  8. Codeforces Global Round 4E(字符串,思维)

    #include<bits/stdc++.h>using namespace std;string s,a,b;int main(){ cin>>s; int n=s.size ...

  9. e_book

    1. 奢侈的纸制书籍 2. 电子书 2.1 与印刷书籍的比较 2.2 电子书格式 2.2.1 Kindle 2.2.2 PDF 2.2.3 EPUB 2.2.4 更多电子书格式比较 2.3 公共领域的 ...

  10. Nodejs 开发 随手记

    console.log(Object.prototype.toString.call(Now.toString())); //类型判断