首页 > TAG信息列表 > poj1985

POJ1985 Cow Marathon (树的直径)

用两次dfs求出树的直径,这两次dfs可以写在一起,当然为了方便理解,这里是分开写的。 1 //两次dfs求树的重心 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 7 const int N=40005,M=40005*2; 8 int n,m,tot,p,ed; 9 int d[N],he