Misha, Grisha and Underground 题意:Misha 和 Grisha 是2个很喜欢恶作剧的孩子, 每天早上 Misha 会从地铁站 s 通过最短的路到达地铁站 f, 并且在每个地铁站上都写上一句话, 然后Grisha 再从地铁站 t 通过最短的路到达地铁站 f, 并且记录下路途上被Misha写上字的地铁站数目,并且当天晚上会人会将地铁站清理干净,不会干扰第二天的计数, 现在给你3个地铁站 a, b, c, 现在求Misha记录的数目最大能是多少. 代码:求出Lca(a,…
832D - Misha, Grisha and Underground 思路:lca,求两个最短路的公共长度.公共长度公式为(d(a,b)+d(b,c)-d(a,c))/2. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define ls rt<<1,l,m #define rs rt<<1|1,m+1,r const int INF=0x3f3f3f3f; ; ; ve…
Misha, Grisha and Underground time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected…
D. Misha, Grisha and Underground time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connec…
D. Misha, Grisha and Underground 这个题目算一个树链剖分的裸题,但是这个时间复杂度注意优化. 这个题目可以选择树剖+线段树,时间复杂度有点高,比较这个本身就有n*logn*logn 但是就是lca+一点点思维就完全不卡时间. #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <algorithm&g…
Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected with n - 1 routes so that each route connects two stations, and it is possible to reach every station from any other. The boys decided to h…
Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected with n - 1 routes so that each route connects two stations, and it is possible to reach every station from any other. The boys decided to h…
[Link]:http://codeforces.com/contest/832/problem/D [Description] 给你一棵树; 然后给你3个点 让你把这3个点和点s,t,f对应; 然后s先从s走到f; 之后t再从t走到f; 求这两条路径的公共路径的长度; [Solution] 答案为 dis(s,f)+dis(t,f)−dis(s,t)2 树上最短路径做一下就好; LCA! [NumberOf WA] 0 [Reviw] 想得太慢了 [Code] #include <cstdio…
题目链接 模板copy from http://codeforces.com/contest/832/submission/28835143 题意,给出一棵有n个结点的树,再给出其中的三个结点 s,t,f ,求路径 (s,t) (s,f) (t,f) 三者的最大公共结点数 对于(t,f) (s,f)的公共结点数,有 懒得细想了,暴力对s,t,f生成排列(反正一共仨数,最多也就3!=6个排列),求各种情况下的最大ans #include<bits/stdc++.h> using namespac…
我奇特的脑回路的做法就是 树链剖分 + 树状数组 树状数组是那种 区间修改,区间求和,还有回溯的 当我看到别人写的是lca,直接讨论时,感觉自己的智商收到了碾压... #include<cmath> #include<map> #include<iostream> #include<cstring> #include<cstdio> #include<set> #include<vector> #include<qu…