include iostream include vector using namespace std struct node long l

 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <vector>
using namespace std;
struct node
{
long long okl;
long long childAdd;
double average;
int parent;
vector<int> child;
node()
{
okl = 0;
childAdd = 0;
average = -1;
parent = -1;
}
};
node empl[50008];
double getChildAverage(int v)
{
if(empl[v].average > 0)
return empl[v].average;
if(empl[v].child.empty())
return empl[v].okl;
empl[v].average = empl[v].okl;
for(auto i = empl[v].child.begin(); i != empl[v].child.end(); ++i)
empl[v].average += *i;
}
int main()
{
int n, queries, first;
cin >> n >> queries >> first;
empl[0].okl = first;
for(int i = 1; i <= n; ++i)
{
int par, zrp;
cin >> par >> zrp;
empl[i].okl = zrp;
empl[par].child.push_back(i);
}
return 0;
}