题解 CF938G 【Shortest Path Queries】】的更多相关文章

这两道都用到了线段树分治和按秩合并可撤销并查集. Shortest Path Queries 给出一个连通带权无向图,边有边权,要求支持 q 个操作: x y d 在原图中加入一条 x 到 y 权值为 d 的边 x y 把图中 x 到 y 的边删掉 x y 表示询问 x 到 y 的异或最短路 保证任意操作后原图连通无重边自环且操作均合法 n,m,q≤200000 题解 与WC2011 最大XOR和路径一样,先考虑没有加边删边的做法 做出原图的任意一棵生成树 把每个非树边和树边形成的环丢进线性基里…
首先只有询问的话就是个WC的题,线性基+生成树搞一搞就行. 进一步,考虑如果修改操作只有加边怎么做. 好像也没有什么变化,只不过需要在线地往线性基里插入东西而已. 删边呢? 注意到线性基这个玩意是不支持删除操作的. 对于这种不好删除的的东西有种不错的解决方法,就是线段树分治. 把每个操作劈成logn个区间以后来搞一下. 按照线段树分治的套路,通过遍历整棵线段树来获得答案. 发现需要一个可以动态维护支持加/删边的生成树的东西. 能做到这个的无非就两个数据结构,按秩合并的并查集和LCT. 这里使用按…
正解:线段树分治+线性基 解题报告: 传送门$QwQ$ 考虑如果只有操作3,就这题嘛$QwQ$ 欧克然后现在考虑加上了操作一操作二 于是就线段树分治鸭 首先线段树叶子节点是询问嘛这个不用说$QwQ$.然后把每条边放到所有它存在的区间上. 然后处理询问的话就$dfs$遍历线段树,删边操作就可以直接按栈序撤销了 最后梳理下这题的大致思路趴$QwQ$.首先以询问为节点建一棵线段树,并把每条边放到所有它会出现的节点处,然后$dfs$整棵线段树计算答案. 具体说下$dfs$的过程趴$QwQ$. 首先显然是…
[CF938G]Shortest Path Queries(线段树分治,并查集,线性基) 题面 CF 洛谷 题解 吼题啊. 对于每个边,我们用一个\(map\)维护它出现的时间, 发现询问单点,边的出现时间是区间,所以线段树分治. 既然路径最小值就是异或最小值,并且可以不是简单路径, 不难让人想到\(WC2011\)那道最大\(Xor\)路径和. 用一样的套路,我们动态维护一棵生成树,碰到一个非树边, 就把这个环的异或和丢到线性基里面去,这样子直接查就好了. 动态维护生成树直接用并查集就好了,没…
题目让我们维护一个连通无向图,边有边权,支持加边删边和询问从\(x\)到\(y\)的异或最短路. 考虑到有删边这样的撤销操作,那么用线段树分治来实现,用线段树来维护询问的时间轴. 将每一条边的出现时间段标记到线段树上,表示在这一段询问中这条边存在. 异或最短路的处理方法与最大XOR和路径类似,给线段树上每个节点开一个线性基,找出当前所有的环,插入该节点的线性基,查询时任意找出一条从\(x\)到\(y\)的路径,到线性基中查询,即为答案. 具体实现时用可撤销并查集,采用按秩合并来优化,因为路径压缩…
洛谷 Codeforces 分治的题目,或者说分治的思想,是非常灵活多变的. 所以对我这种智商低的选手特别不友好 脑子不好使怎么办?多做题吧-- 前置知识 线性基是你必须会的,不然这题不可做. 推荐再去看看洛谷P4151. 思路 看到异或最短路,显然线性基. 做题多一些的同学想必已经想到了"洛谷P4151 [WC2011]最大XOR和路径"了. 先考虑没有加边删边的做法: 做出原图的任意一棵生成树: 把每个非树边和树边形成的环丢进线性基里: 询问时把两点在树上的路径异或和丢进线性基里求…
又到了喜闻乐见的写博客清醒时间了233,今天做的依然是线段树分治 这题算是经典应用了吧,假的动态图(可离线)问题 首先不难想到对于询问的时间进行线段树分治,这样就可以把每一条边出现的时间区间扔进线段树里,考虑如何维护答案 初步的想,图上两点间异或最小值,和最大值类似.先求出一棵生成树,然后把环扔进线性基里,每次查询两点间异或值之后再扔进线性基里求最小值即可 正确性的话,因为这样环一定是有树边+非树边构成的,我们可以在任意一个点走到一个环再绕回来,中间重复走的树边因为走了两次相当于没有影响 然后我…
Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 131072/131072 K (Java/Others) Problem Description There is a path graph G=(V,E)G=(V,E) with nn vertices. Vertices are numbered from 11 to nn and there…
Shortest Path 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5636 Description There is a path graph G=(V,E) with n vertices. Vertices are numbered from 1 to n and there is an edge with unit length between i and i+1 (1≤i<n). To make the graph more in…
Shortest Path Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1494    Accepted Submission(s): 476 Problem Description There is a path graph G=(V,E) with n vertices. Vertices are numbered from…
How Many Shortest Path 标签: 网络流 描述 Given a weighted directed graph, we define the shortest path as the path who has the smallest length among all the path connecting the source vertex to the target vertex. And if two path is said to be non-overlapping…
Shortest Path Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 627    Accepted Submission(s): 204 Problem Description There is a path graph G=(V,E) with n vertices. Vertices are numbered from 1…
A. Shortest path of the king 题目连接: http://www.codeforces.com/contest/3/problem/A Description The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he…
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 13070    Accepted Submission(s): 2794 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4725 Description: This is a ve…
原题链接在这里:https://leetcode.com/problems/shortest-path-with-alternating-colors/ 题目: Consider a directed graph, with nodes labelled 0, 1, ..., n-1.  In this graph, each edge is either red or blue, and there could be self-edges or parallel edges. Each [i,…
We all love short and direct problems, it is easier to write, read and understand the problem statement.Here is one of these problems. \Life is too short to make a story", said Ahmed Aly.You are given a weighted directed graph of N nodes (the nodes a…
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que camb…
The Shortest Path Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2440    Accepted Submission(s): 784 Problem Description There are N cities in the country. Each city is represent by a matrix si…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1760 Given a weighted directed graph, we define the shortest path as the path who has the smallest length among all the path connecting the source vertex to the target vertex. And if two…
Problem Description This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algoritmo. If you do not understand a word of this paragraph, just move on.The Nya graph is an un…
题目链接:pid=3631" style="font-size:18px">http://acm.hdu.edu.cn/showproblem.php?pid=3631 Shortest Path Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3962    Accepted Submission(s): 9…
Description This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algoritmo. If you do not understand a word of this paragraph, just move on. The Nya graph is an undirecte…
An undirected, connected graph of N nodes (labeled 0, 1, 2, ..., N-1) is given as graph. graph.length = N, and j != i is in the list graph[i] exactly once, if and only if nodes i and j are connected. Return the length of the shortest path that visits…
1.概述 路由协议OSPF全称为Open Shortest Path First,也就开放的最短路径优先协议,因为OSPF是由IETF开发的,所以所有厂商都可以用. OSPF的流量使用IP协议号. OSPF对网络没有跳数限制,支持 Classless Interdomain Routing (CIDR)和Variable-Length Subnet Masks (VLSMs),没有自动汇总功能,可以手动汇总. OSPF并不会周期性更新路由表,而采用增量更新,即只在路由有变化时,才会发送更新,并且…
Given a knight in a chessboard (a binary matrix with 0 as empty and 1 as barrier) with a source position, find the shortest path to a destinationposition, return the length of the route. Return -1 if knight can not reached. Notice source and destinat…
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13445    Accepted Submission(s): 2856 Problem Description This is a very easy problem, your task is just calculate…
2018-10-06 22:04:38 问题描述: 问题求解: 本题要求是求遍历所有节点的最短路径,由于本题中是没有要求一个节点只能访问一次的,也就是说可以访问一个节点多次,但是如果表征两次节点状态呢?可以使用(curNode, VisitedNode)来进行表征,如果两次的已经访问的节点相同那么就没有必要再进行访问了,最终的状态就是所有节点都访问过了. 另外,由于起点对结果是有影响的,因此在最开始需要将所有的节点都压栈. public int shortestPathLength(int[][…
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 37    Accepted Submission(s): 6 Problem Description This is a very easy problem, your task is just calculate el cam…
Shortest Path Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1146 Accepted Submission(s): 358 Problem Description There is a path graph G=(V,E) with n vertices. Vertices are numbered from 1 to…
人老了就比较懒,故意挑了到看起来很和蔼的题目做,然后套个spfa和dinic的模板WA了5发,人老了,可能不适合这种刺激的竞技运动了…… 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2760 Description Given a weighted directed graph, we define the shortest path as the path who has the smallest leng…