【牛客 - 1080D】tokitsukaze and Event(最短路,思维)

题干:

链接:https://ac.nowcoder.com/acm/contest/1080/D
来源:牛客网
 

这天,tokitsukaze带着她的舰队去才归一儿海探索。这个海域有n个站点,深海舰队控制着这片海域的m条航线,这些航线连接着这n个点,第i条航线连接着ui,vi两个点。航线都是正确的,也就是说没有重复的航线,也没有任何一个点与自己相连。tokitsukaze的舰队经过第i条航线时,会受到来自深海舰队的ai点伤害。

tokitsukaze可以在某个休息站点将接下来的战斗切换至夜战模式,这样在她的舰队经过第i条航线时,受到的伤害就变为bi,不过一旦切换到夜战模式就不能再次切换回来,所以她必须考虑清楚在哪里切换。

现在有个限时活动。活动难度分为1,2,3,4,...n,在难度1下,tokitsukaze可以在任意站点切换到夜战模式,而在难度2下,不能在站点1切换到夜战模式,在难度3下,不能在站点1,2切换模式...以此类推,即在难度k下,tokitsukaze不能在站点1,2,3,4,5...k-1切换模式。同时,活动还要求在游戏结束时必须处于夜战模式。

现在tokitsukaze的舰队从s点出发,要前往深海大本营所在的t点。请你告诉她,在难度为1,2,3,4,5...n时,她的舰队结束游戏时受到的最小伤害。

输入描述:

第一行包括2个正整数n,m,(2≤n≤10^5,1≤m≤min(n*(n-1)/2,10^5))。
接下来m行,每行包括4个正整数u,v,a,b,(1≤u,v≤n,1≤a,b≤10^9)。
最后一行包括2个正整数s,t,(1≤s,t≤n)。

输出描述:

请你告诉tokitsukaze,在难度为1,2,3,4,5...n时,她的舰队处于夜战模式结束游戏受到的最小伤害。

示例1

输入

复制

4 3
1 4 1 30
1 2 1 10
1 3 20 1
2 3

输出

复制

2
11
21
33

说明

活动难度为1时,在编号为1的点切换模式,受到的最小伤害为2。
活动难度为2时,在编号为2的点切换模式,受到的最小伤害为11。
活动难度为3时,在编号为3的点切换模式,受到的最小伤害为21。
活动难度为4时,在编号为4的点切换模式,受到的最小伤害为33。

示例2

输入

复制

4 3
1 4 30 1
1 2 10 1
1 3 20 1
3 1

输出

复制

1
1
1
51

说明

活动难度为1时,在编号为3的点切换模式,受到的最小伤害为1。
活动难度为2时,在编号为3的点切换模式,受到的最小伤害为1。
活动难度为3时,在编号为3的点切换模式,受到的最小伤害为1。
活动难度为4时,在编号为4的点切换模式,受到的最小伤害为51。路线是3-1-4-1。因为必须处于夜战模式结束游戏,所以在到达1后还要拐去4去切换模式。

解题报告:
因为有点懒而且比较水所以直接改改官方题解。
s为起点,用边权a跑一遍最短路,记为disa​。
把边的方向反转,t为起点,用边权b跑一遍最短路,记为disb​。(但是这题是双向边所以并不用反转)
那么在节点 i 切换模式的最小伤害为​disai+disbi,再做一遍后缀min即可。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
struct Edge {int v,ne;ll a,b;
} e[MAX];
struct Point {int u;ll c;Point(){}Point(int u,ll c):u(u),c(c){}bool operator<(const Point & b) const {return c > b.c;}
};
int tot,head[MAX];
void add(int u,int v,ll a,ll b) {e[++tot].v = v;e[tot].a = a;e[tot].b = b;e[tot].ne = head[u];head[u] = tot;
}
ll disa[MAX],disb[MAX];
bool vis[MAX];
void Dija(int st,int ed) {memset(disa,0x3f,sizeof disa);memset(vis,0,sizeof vis);priority_queue<Point> pq;pq.push(Point(st,0));
//	vis[st] = 1;disa[st] = 0;while(!pq.empty()) {Point cur = pq.top();pq.pop();if(vis[cur.u] == 1) continue;vis[cur.u] = 1;for(int i = head[cur.u]; ~i; i = e[i].ne) {int v = e[i].v;if(vis[v] || disa[v] <= disa[cur.u] + e[i].a) continue;disa[v] = disa[cur.u] + e[i].a;pq.push(Point(v,disa[v]));}}
}
void Dijb(int st,int ed) {memset(disb,0x3f,sizeof disb);memset(vis,0,sizeof vis);priority_queue<Point> pq;pq.push(Point(st,0));
//	vis[st] = 1;disb[st] = 0;while(!pq.empty()) {Point cur = pq.top();pq.pop();if(vis[cur.u] == 1) continue;vis[cur.u] = 1;for(int i = head[cur.u]; ~i; i = e[i].ne) {int v = e[i].v;if(vis[v] || disb[v] <= disb[cur.u] + e[i].b) continue;disb[v] = disb[cur.u] + e[i].b;pq.push(Point(v,disb[v]));}}
}
ll ans[MAX];
int main()
{int n,m,st,ed;memset(head,-1,sizeof head);cin>>n>>m;for(int a,b,c,d,i = 1; i<=m; i++) {scanf("%d%d%d%d",&a,&b,&c,&d);add(a,b,c,d);add(b,a,c,d);}scanf("%d%d",&st,&ed);Dija(st,ed);Dijb(ed,st);ans[n] = disa[n]+disb[n];for(int i = n-1; i>=1; i--) {ans[i] = min(ans[i+1],disa[i]+disb[i]);}for(int i = 1; i<=n; i++) printf("%lld\n",ans[i]);return 0 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/439861.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

4.深度学习练习:Building your Deep Neural Network: Step by Step(强烈推荐)

本文节选自吴恩达老师《深度学习专项课程》编程作业&#xff0c;在此表示感谢。 课程链接&#xff1a;https://www.deeplearning.ai/deep-learning-specialization/ fter this assignment you will be able to: Use non-linear units like ReLU to improve your modelBuild a d…

一步步编写操作系统21 x86虚拟机bochs 跟踪bios

为了让大家更好的理解bios是怎样被执行的&#xff0c;也就是计算机中第一个软件是怎样开始的&#xff0c;咱们还是先看下图3-17。在图的上面第5行&#xff0c;显示的是下一条待执行的指令&#xff0c;这是程序计数器&#xff08;PC&#xff09;中的值&#xff0c;在x86上的程序…

【CodeForces - 361D】Levko and Array (二分,dp)

题干&#xff1a; Levko has an array that consists of integers: a1, a2, ... , an. But he doesn’t like this array at all. Levko thinks that the beauty of the array a directly depends on value c(a), which can be calculated by the formula: The less value…

5.深度学习练习:Deep Neural Network for Image Classification: Application

本文节选自吴恩达老师《深度学习专项课程》编程作业&#xff0c;在此表示感谢。 课程链接&#xff1a;https://www.deeplearning.ai/deep-learning-specialization/ After this assignment you will be able to: Build and apply a deep neural network to supervised learning…

排序集锦(各种排序算法的特点及性能分析)

关于排序&#xff0c;似乎很简单的很常见的概念&#xff0c;却蕴含着很多技术&#xff0c;下面是从不同的角度&#xff0c;对排序的总结&#xff1a; 直插希 冒泡快 选择堆 1 按照排序特性分类 首先按照排序本身的操作特性可以分为下面几种&#xff1a; 插入排序 直接插入排…

【CodeForces - 689D】Friends and Subsequences(RMQ,二分 或单调队列)

题干&#xff1a; Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) — who knows? Every one of them has an integer seque…

6.深度学习练习:Initialization

本文节选自吴恩达老师《深度学习专项课程》编程作业&#xff0c;在此表示感谢。 课程链接&#xff1a;https://www.deeplearning.ai/deep-learning-specialization/ 目录 1 - Neural Network model 2 - Zero initialization 3 - Random initialization&#xff08;掌握&…

Java Object类的各个方法

Java中所有的类都继承自java.lang.Object类&#xff0c;Object类中一共有11个方法&#xff1a; public final native Class<?> getClass();public native int hashCode();public boolean equals(Object obj) {return (this obj); }protected native Object clone() th…

【CodeForces - 602D】Lipshitz Sequence(思维,单调栈,斜率单调性)

题干&#xff1a; A function is called Lipschitz continuous if there is a real constant Ksuch that the inequality |f(x) - f(y)| ≤ K|x - y| holds for all . Well deal with a more... discrete version of this term. For an array , we define its Lipschi…

7.深度学习练习:Regularization

本文节选自吴恩达老师《深度学习专项课程》编程作业&#xff0c;在此表示感谢。 课程链接&#xff1a;https://www.deeplearning.ai/deep-learning-specialization/ 目录 1-Package 2 - Non-regularized model 3 - L2 Regularization&#xff08;掌握&#xff09; 4-Dropou…

深入详解JVM内存模型与JVM参数详细配置

本系列会持续更新。 JVM基本是BAT面试必考的内容&#xff0c;今天我们先从JVM内存模型开启详解整个JVM系列&#xff0c;希望看完整个系列后&#xff0c;可以轻松通过BAT关于JVM的考核。 BAT必考JVM系列专题 1.JVM内存模型 2.JVM垃圾回收算法 3.JVM垃圾回收器 4.JVM参数详解 5…

【2019牛客暑期多校训练营(第三场)- A】Graph Games(思维,对边分块)

题干&#xff1a; 链接&#xff1a;https://ac.nowcoder.com/acm/contest/883/A 来源&#xff1a;牛客网 You are given an undirected graph with N\ N N vertices and M\ M M edges. The edges are numbered from 1\ 1 1 to M\ M M . Denote the set S(x)\ S(x) S…

8.深度学习练习:Gradient Checking

本文节选自吴恩达老师《深度学习专项课程》编程作业&#xff0c;在此表示感谢。 课程链接&#xff1a;https://www.deeplearning.ai/deep-learning-specialization/ 目录 1) How does gradient checking work? 2) 1-dimensional gradient checking 3) N-dimensional gradie…

苹果手机看电流判断故障

正常的开机电流 1、按开机键后电流在40mA摆动一下&#xff08;CPU供电正常&#xff09;&#xff1b; 2、到80mA左右摆动一下&#xff08;暂存开始工作&#xff0c;也就是CPU上盖&#xff0c;然后开始进行总线的初始化&#xff09;&#xff1b; 3、指针到120mA左右摆动&#xff…

【CodeForces - 675C】Money Transfers(思维,前缀和)

题干&#xff1a; There are n banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank n are neighbours if n > 1. No bank is a neighbou…

9.深度学习练习:Optimization Methods

本文节选自吴恩达老师《深度学习专项课程》编程作业&#xff0c;在此表示感谢。 课程链接&#xff1a;https://www.deeplearning.ai/deep-learning-specialization/ 目录 1 - Gradient Descent 2 - Mini-Batch Gradient descent 3 - Momentum 4 - Adam 5 - Model with dif…

一步步编写操作系统 22 硬盘操作方法

硬盘中的指令很多&#xff0c;各指令的用法也不同。有的指令直接往command寄存器中写就行了&#xff0c;有的还要在feature寄存器中写入参数&#xff0c;最权威的方法还是要去参考ATA手册。由于本书中用到的都是简单的指令&#xff0c;所以对此抽象出一些公共的步骤仅供参考之用…

10.深度学习练习:Convolutional Neural Networks: Step by Step(强烈推荐)

本文节选自吴恩达老师《深度学习专项课程》编程作业&#xff0c;在此表示感谢。 课程链接&#xff1a;https://www.deeplearning.ai/deep-learning-specialization/ 目录 1 - Packages 2 - Outline of the Assignment 3 - Convolutional Neural Networks 3.1 - Zero-Paddin…

【HDU - 2639】Bone Collector II (第K大背包,dp,STLset)

题干&#xff1a; The title of this problem is familiar,isnt it?yeah,if you had took part in the "Rookie Cup" competition,you must have seem this title.If you havent seen it before,it doesnt matter,I will give you a link: Here is the link: http…

一步步编写操作系统 23 重写主引导记录mbr

本节我们在之前MBR的基础上&#xff0c;做个稍微大一点的改进&#xff0c;经过这个改进后&#xff0c;我们的MBR可以读取硬盘。听上去这可是个大“手术”呢&#xff0c;我们要将之前学过的知识都用上啦。其实没那么大啦&#xff0c;就是加了个读写磁盘的函数而已&#xff0c;哈…