题意:有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. 【Android多线程】异步任务AsyncTask类

    https://www.bilibili.com/video/av65170691?p=9 (本文为此视频观看笔记) 一.为什么需要此类 Handler繁琐 二.理解AsyncTask 2.1 参数( ...

  2. C语言 1字节signed char的范围为什么是-128~127?

    参考 1. 关于 -128 ,+128,-0,+0,-1 的反码补码 | 博客园 2. 八位二进制数为什么表示范围(-128~~+127)理解 | 博客园 无符号单字节范围 无符号单字节unsigne ...

  3. 20 个新的且值得关注的 Vue 开源项目

    译者:前端小智作者:Nastassia Ovchinnikova来源:flatlogic.com 个人专栏 ES6 深入浅出已上线,深入ES6 ,通过案例学习掌握 ES6 中新特性一些使用技巧及原理, ...

  4. Mysql按照字段的重复数排序

    select source_job_number,count(*) as count from v1_user WHERE source_id=3 group by source_job_number ...

  5. MyBatis+Oracle实现主键自增长的几种常用方式

    一.使用selectKey标签 <insert id="addLoginLog" parameterType="map" > <selectK ...

  6. unity 热更方案对比

    现在一般使用的方案有:tulua&ulua.xlua.ILRuntime 对比: tulua&ulua 方案成熟,稳定第三方库支持 xlua 之前是为了热更修复线上bug的,腾讯发起的 ...

  7. SpringBoot中普通类无法通过@Autowired自动注入Service、dao等bean解决方法

    无法注入原因: 有的时候我们有一些类并不想注入Spring容器中,有Spring容器实例化,但是我们又想使用Spring容器中的一些对象,所以就只能借助工具类来获取了 工具类: package com ...

  8. 安装luarocks安装驱动

    yum install libtermcap-devel ncurses-devel libevent-devel readline-devel--安装lua前提条件 LuaSQL 可以使用 LuaR ...

  9. ubuntu修改pip的官方源为豆瓣源

    修改官方源为豆瓣源: 编辑配置文件, 如果没有, 新建一份(我这里没有): mkdir ~/.pipvim ~/.pip/pip.conf 添加内容如下: [global] index-url = h ...

  10. tensorflow中的Fetch、Feed(02-3)

    import tensorflow as tf #Fetch概念 在session中同时运行多个op input1=tf.constant(3.0) #constant()是常量不用进行init初始化 ...