ZOJ 3195 Design the city 题解】的更多相关文章

这个题目大意是: 有N个城市,编号为0~N-1,给定N-1条无向带权边,Q个询问,每个询问求三个城市连起来的最小权值. 多组数据 每组数据  1 < N < 50000  1 < Q < 70000: 一道多源最短路的题目,注意题目数据:N.Q都很大 不能考虑Floyd.SPFA.Dijkstra.Bellman-Ford等最短路算法 再看N-1条边,明显构成一棵树,最短路有且只有一条 很明显需要LCA.... 不懂LCA的点!我!点!我! 我们所熟知的LCA是求两个点的最短路,而…
Design the city Time Limit: 1 Second      Memory Limit: 32768 KB Cerror is the mayor of city HangZhou. As you may know, the traffic system of this city is so terrible, that there are traffic jams everywhere. Now, Cerror finds out that the main reason…
Cerror is the mayor of city HangZhou. As you may know, the traffic system of this city is so terrible, that there are traffic jams everywhere. Now, Cerror finds out that the main reason of them is the poor design of the roads distribution, and he wan…
题目链接 : ZOJ Problem Set - 3195 题目大意: 求三点之间的最短距离 思路: 有了两点之间的最短距离求法,不难得出: 对于三个点我们两两之间求最短距离 得到 d1 d2 d3 那么最短距离就是 d = ( d1 + d2 + d3 ) / 2 要注意每个数组的范围大小,因为这个问题手抖敲错,TLE+RE一整页/(ㄒoㄒ)/~~ 用前向星来保存边和询问,空间卡的也很严 如下图所示:所求路线为紫色,等于蓝色+黄色+绿色之和的一半 代码: #include <bits/stdc…
题意:给定n个点,下面n-1行 u , v ,dis 表示一条无向边和边权值,这里给了一颗无向树 下面m表示m个询问,问 u v n 三点最短距离 典型的LCA转RMQ #include<stdio.h> #include<string.h> #include<math.h> #define N 100000 #define INF 1<<29 #define Logo 17 using namespace std; inline int Min(int a…
题目要对每次询问将一个树形图的三个点连接,输出最短距离. 利用tarjan离线算法,算出每次询问的任意两个点的最短公共祖先,并在dfs过程中求出离根的距离.把每次询问的三个点两两求出最短距离,这样最终结果就是3个值一半. 其实开始我用的一种很挫的方法才AC的,具体思路就不说了,感觉很麻烦又不好写的样子.怎么没想到上面的简便方法呢. 初始代码: #include <iostream> #include <sstream> #include <cstdio> #includ…
题目链接 给一棵树, m个询问, 每个询问给出3个点, 求这三个点之间的最短距离. 其实就是两两之间的最短距离加起来除2. 倍增的lca模板 #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map> #include <s…
Design the city Time Limit: 1 Second      Memory Limit: 32768 KB Cerror is the mayor of city HangZhou. As you may know, the traffic system of this city is so terrible, that there are traffic jams everywhere. Now, Cerror finds out that the main reason…
Design the city Time Limit: 1 Second      Memory Limit: 32768 KB Cerror is the mayor of city HangZhou. As you may know, the traffic system of this city is so terrible, that there are traffic jams everywhere. Now, Cerror finds out that the main reason…
C - Design the city Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Description Cerror is the mayor of city HangZhou. As you may know, the traffic system of this city is so terrible, that there are traffic jams everywhere.…