摘要:
树的直径是求一棵树最远的两点之间的距离。 套路:两次dfs,一次dfs求离根最远的结点A,再以A为根搜索离A最远的结点B,A到B就是树的直径(双向的树) #include<bits/stdc++.h> using namespace std; const int N=100010; int n; s 阅读全文
摘要:
https://www.acwing.com/problem/content/839/ #include<iostream> using namespace std; const int N=100010; int n,m; int p[N],cnt[N]; int find(int x){ if( 阅读全文