hiho Week 11 register

Ended

Participants:433

Verdict:Accepted
Score:100 / 100
Submitted:2014-09-14 10:47:34

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#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++) {
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX