hiho week 309 register

Ended

Participants:37

Verdict:Accepted
Score:100 / 100
Submitted:2020-05-30 22:11:32

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>
#include <cstdio>
using namespace std;
int a[100010];
vector<int> arr[100010];
int du[100010];
int fa[100010]; 
long long ans;
long long find(int z)
{
    if(du[z] == 0)
    {
        return a[z]; 
    }
    long long mt=0,t=0;
    vector<int> ch = arr[z];
    for(int i=0;i<ch.size();i++)
    {
        t = find(ch[i]);
//      cout<<ch[i]<<"---"<<t<<endl;
        if(t>mt)
        {
            ans += i*(t-mt);
            mt = t;
        }else{
            ans += mt-t;
        }
    }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX