![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
树的直径
吴俊达9812
这个作者很懒,什么都没留下…
展开
-
luogu P1099 树网的核
树的直径的结论: 1.所有直径相较于一点,且为边的中点。 2.以直径上一点为根的子树,深度不超过这一点到较近的端点的距离。 #include <bits/stdc++.h> using namespace std; typedef long long LL; const int maxn = 500005; const int maxm = 1000005; int he[ma...原创 2019-10-23 20:38:18 · 102 阅读 · 0 评论 -
luogu P3629 [APIO2010]巡逻
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; const int maxm = 200005; int he[maxn],ver[maxm],ne[maxm],cost[maxm],tot=1; void add( int x,int y,int z ){ ver[++tot] =...原创 2019-10-23 19:34:32 · 121 阅读 · 0 评论 -
hdu 6686 Rikka with Travels
这里总结一下树的直径的一些性质 1.从任意一点出发,到达的最大深度的点,一定可以作为树的直径的一个端点。 2.两棵树之间连接一条线,合并之后的树的直径一定可以有原来两棵树的4个直径端点构成。 思路:首先,若其中一条路径与原来直径不相交,那么其中一条线一定选为直径。否则两条路径都与直径相交。最后求矩形面积并的时候需要从后向前遍历,从前往后做不了。 #include <bits/st...原创 2019-08-20 12:26:09 · 391 阅读 · 0 评论