树的直径两遍dfs救星了 至于一定在直径中的边数,可以发现这些边一定是连续的(不然你两条直径中间能有空挡?),然后,如果某个点往下有多条直径,那么这条点以下都不算入答案.所以以直径分别两端点为根,找出这样离根最近的点(注意最远的点就是另一个端点),然后找到那两个点的距离就是答案 // luogu-judger-enable-o2 #include<bits/stdc++.h> #define LL long long #define il inline #define re register
看了child学长的题解才知道怎么写TAT http://www.cnblogs.com/ctlchild/p/5160272.html 以前不知道直径都是过重心的..代码改着改着就和标程完全一样了QAQ #include<cstdio> #include<iostream> #include<cstring> #define ll long long using namespace std; ; struct zs{ int too,pre,dis; }e[maxn&
本以为必有高论,结果是个思博题.随便找一条直径,最后答案肯定是这条直径上的连续一段,如果某分支长度等于直径上某端的长度这一端都要被剪掉. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll long long