[Offer收割]编程练习赛24 register

Ended

Participants:356

Verdict:Accepted
Score:100 / 100
Submitted:2017-08-27 13:12:39

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 <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define LL long long
int n,et=0;
struct edge
{
    int v,next;
}e[200005];
int first[100005],a[100005];
LL f[100005];
bool isRoot[100005];
LL dfs(int u)
{
    LL res = 0;
    for (int i = first[u];i ;i = e[i].next)
    {
        res += dfs(e[i].v);
        f[u] = max(f[u],f[e[i].v]);
    }
    for (int i = first[u];i ;i = e[i].next)
        res += f[u] - f[e[i].v];
    f[u] += a[u];
    return res;
}
int main()
{
    scanf("%d",&n);
    memset(first,0,sizeof(first));
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX