树的直径
青烟绕指柔!
我不怕千万人阻挡,只怕自己投降。
展开
-
牛客练习赛67
题目链接:牛客练习赛67A:模拟,注意全0的情况。#pragma GCC optimize("-Ofast","-funroll-all-loops")#include<bits/stdc++.h>//#define int long longusing namespace std;string str;int ch(char c){return c<'0'||c>'9';}void solve(){ int ok=0,st=0;; for(int i=0;i&原创 2020-08-14 22:48:50 · 189 阅读 · 0 评论 -
旅游规划
题目链接:旅游规划显然我们可以先求出直径,然后枚举每一个点。要么是儿子之间组成最大长度,要么是最大的儿子加祖先过来的长度。树dp一遍,然后换根即可。AC代码:#pragma GCC optimize("-Ofast","-funroll-all-loops")#include<bits/stdc++.h>using namespace std;const int N=2e5+10;int n,vis[N],mx1[N],mx2[N],mx[N],d;vector<i原创 2020-05-29 18:25:35 · 283 阅读 · 0 评论 -
请求
题目链接:请求动态维护LCA的倍增数据,然后每个联通块的直径。即可。当然,如果闲的没事做,可以直接LCT维护直径。AC代码:#pragma GCC optimize("-Ofast","-funroll-all-loops")#include<bits/stdc++.h>//#define int long longusing namespace std;const...原创 2020-05-05 17:44:19 · 101 阅读 · 0 评论 -
漂亮的公园
题目链接:漂亮的公园把两种颜色的点,看成两颗树做合并,所以答案就是合并之后的直径。所以我们需要维护直径,然后直接就只和原树的两个点有关,直接预处理即可。一般有两种方法:先求深度最大的点,必然在直径上,然后找另一个。或者一直维护直径的两个端点。注释的地方是第一种方法。常数更小。AC代码:#pragma GCC optimize("-Ofast","-funroll-all-loop...原创 2020-05-03 23:34:04 · 228 阅读 · 0 评论 -
Adjoin the Networks
题目链接:Adjoin the Networks显然两颗树相连,要使得最后直径最小只能是直径中点互相相连。假设有三颗树,直径分别为:a,b,c那么如果按照 a,b,c去连接,化简式子我们就能发现从大到小连是最优的。但是要注意两个相连的答案是 max(max(a,b),(a+1)/2+(b+1)/2+1)。不能单独是后面一项。所以用堆维护最大值即可。AC代码:#pragma GC...原创 2020-04-28 15:32:05 · 255 阅读 · 0 评论 -
Codeforces - Anton and Tree
题目链接:Codeforces - Anton and Tree显然,相同颜色可以缩点。然后变成一张相邻两点都不同的树。多画一下可以发现答案就是树的直径/2.AC代码:#pragma GCC optimize("-Ofast","-funroll-all-loops")#include<bits/stdc++.h>//#define int long longusin...原创 2020-02-04 12:49:10 · 165 阅读 · 0 评论 -
小雀和他的王国
题目描述年纪轻轻的小雀当上了国王。小雀的王国中一共有n座城市(编号为1~n),被m条双向的高速公路连接,任意两个城市之间都可以通过若干条高速公路互相到达。但是在小雀的王国里,经常发生自然灾害。一次突发的自然灾害会随机破坏一条高速公路,并且有可能使得某两个城市之间无法到达彼此,这样整个王国就不能继续正常运转了。小雀为此很是苦恼。于是小雀决定再修建一条高速公路,连接某两个城市,使得下一次突发自...原创 2019-12-27 23:47:44 · 281 阅读 · 0 评论 -
ICPC Russia Equidistant
In 2019 ICPC subregions structure was changed a little. Now for each subregion, we need to choose the best place for the subregion finals. To make things fair we want to choose a city in such a way th...原创 2019-11-28 16:45:50 · 243 阅读 · 0 评论 -
HDU - 2196 Computer
ComputerTime Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 38471 Accepted Submission(s): 6981Problem DescriptionA school bought the first co...原创 2019-10-09 19:00:38 · 136 阅读 · 0 评论 -
Highway
HighwayIn ICPCCamp there were n towns conveniently numbered with 1,2,…,n connected with (n−1) roads. The i-th road connecting towns ai and bi has length ci. It is guaranteed that any two cities reach...原创 2019-10-04 20:30:46 · 264 阅读 · 0 评论 -
Codeforces - D. Book of Evil
D. Book of Eviltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPaladin Manao caught the trail of the ancient Book of Evil in a swampy area. T...原创 2019-09-21 13:18:23 · 337 阅读 · 0 评论 -
POJ 2631
Roads in the NorthTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 6281 Accepted: 2950DescriptionBuilding and maintaining roads among communities in the far North is an expensive busine...原创 2019-08-13 15:58:05 · 189 阅读 · 0 评论