Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <cstdio>#include <cstring>#include <vector>using namespace std;int ans = 0;vector<int> *m;int f(int a, int pre) {int max1 = 0, max2 = 0, r;vector<int>::iterator it = m[a].begin();while (it != m[a].end()) {if (*it != pre) {r = f(*it, a);if (r > max1)max2 = max1, max1 = r;else if (r > max2)max2 = r;}it++;}if (max1+max2 > ans) ans = max1+max2;return max1+1;}int main() {int n;scanf("%d", &n);m = new vector<int>[n+1];for (int a, b, i = 1; i < n; i++) {