hihoCoder Challenge 14 register

Ended

Participants:709

Verdict:Accepted
Submitted:2015-08-30 19:44:59

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 <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
using std::vector;
using std::max;
vector<int> G[100001];
int ans = 0;
int dfs(int node, int depth) {
    int deepest = 0, second_deepest = 0;
    if (G[node].size() == 0) {
        return depth;
    }
    for (int i = 0, l = G[node].size(); i < l; ++i) {
        int child_depth = dfs(G[node][i], depth + 1);
        if (child_depth > deepest) {
            second_deepest = deepest;
            deepest = child_depth;
        } else if (child_depth > second_deepest) {
            second_deepest = child_depth;
        }
    }
    ans = max(ans, deepest + second_deepest - depth);
    return deepest;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX