Codeforces 787D Legacy 线段树 最短路】的更多相关文章

题意: 有\(n(1 \leq n \leq 10^5)\)个点,\(q(1 \leq q \leq 10^5)\)条路和起点\(s\) 路有三种类型: 从点\(v\)到点\(u\)需要花费\(w\) 从点\(v\)到区间\([l,r]\)中的点花费为\(w\) 从区间\([l,r]\)中的点到点\(v\)花费为\(w\) 求起点到各个点的最少花费 分析: 如下图,构建两颗线段树,边的花费都为\(0\) 对于第一种路直接加边即可 对于第二种路,添加从\(v\)到上面线段树对应区间中的点的边 对于…
D. Legacy time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy…
题意: 有n个点,q个询问, 每次询问有一种操作. 操作1:u→[l,r](即u到l,l+1,l+2,...,r距离均为w)的距离为w: 操作2:[l,r]→u的距离为w 操作3:u到v的距离为w 最终求起点到其他点的最短距离,到达不了输出-1 题解 线段树优化建图+最短路... 不知道这种东西,百度了一下,好像最早的是POI2015的PUS,然后2017/2018的oi也都出过, 还是要见识一下的... 顺便记录一下,封装好的djisktra和graph 代码如下: #include <bit…
题目链接 \(Description\) 有\(n\)个点.你有\(Q\)种项目可以选择(边都是有向边,每次给定\(t,u,v/lr,w\)): t==1,建一条\(u\to v\)的边,花费\(w\): t==2,由\(u\)向\([l,r]\)中任意一些点连边,每次花费\(w\): t==3,由\([l,r]\)中任意一些点向u连边,每次花费\(w\). 最后求使给定的\(s\)到达点\(i(1\leq i\leq n)\)的最小花费. \(Solution\) 花费看成每条边的边权,全都连…
题意:给N个点和Q条选项,有三种类型的选项:1.从u到v花费w修建一条路:2.从u到下标区间为[L,R]的点花费w修建一条路; 3.从下标区间为[L,R]的点到u花费w修建一条路. 然后求起点s到其余点的最短路. 如果直接暴力建图,建图本身就会超时.对于区间上的操作,考虑用线段树解决.线段树上的结点本身就能代表一段区间的点,所以在建图时,用树上的结点充当中间结点.(有点网络流的思想?) 因为要建一张有向图,所以图的点到树上结点要连边,反之亦然:但是在一棵线段树上双向连边就不能对所有的点跑最短路了…
题目大意: 给定一个\(n\)的点的图.求\(s\)到所有点的最短路 边的给定方式有三种: \(u \to v\) \(u \to [l,r]\) \([l,r] \to v\) 设\(q\)为给定边的次数,有\(n,q \leq 10^5\) 题解 类比于线段树优化网络流建图 写一个线段树优化最短路建图即可. #include <queue> #include <vector> #include <cstdio> #include <cstring> #i…
题意: 就是给定一张n nn个点的图,求源点s ss到每个点的单源最短路.这张图共有q组边,连边方式有3种: a→b ,边权为w的单向边:a→[l,r] ,即a到连续区间[l,r]中的每一个点都有一条边权为w的边.[l,r]→a,即连续区间[l,r] 中的每一个点都有一条到a 边权为w 的边.注意数据范围n,q≤10^5. 题解 如果暴力连边(将一对多或者多对一的连边拆开分别连边),那么最差情况下,我们的边数将达到O(nq) 级别,连边就直接超出能承受的范围——更不要说再跑最短路了.因此我们考虑…
B. Legacy 题目连接: http://codeforces.com/contest/786/problem/B Description Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad guys catch them. There are…
B. Legacy 题目连接: http://codeforces.com/contest/786/problem/B Description Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad guys catch them. There are…
D. Legacy time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy…