hiho Week 11 register

Ended

Participants:433

Verdict:Accepted
Score:100 / 100
Submitted:2014-09-20 13:04: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 <iostream>
#include <vector>
using namespace std;
const int N = 110000;
vector<int>edge[N];
int max(int x, int y){
    return x > y ? x : y;
}
int ans;
int dfs(int now, int pre){
    int l = -1, r = -1;
    for (int i = 0; i < edge[now].size(); i++){
        if (edge[now][i] == pre) continue;
        int t = dfs(edge[now][i], now);
        if (t >= l){
            r = l;
            l = t;
        }
        else if (t>r){
            r = t;
        }
    }
    if (ans <= l + r + 2) ans = l + r + 2;
    return l + 1;
}
int main(){
    int n,a,b;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX