# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1116025 | 2024-11-21T07:56:33 Z | simona1230 | Magic Tree (CEOI19_magictree) | C++17 | 246 ms | 63848 KB |
#include <bits/stdc++.h> #define endl '\n' using namespace std; long long n,m,k; long long d[100001]; long long w[100001]; vector<long long> v[100001]; void read() { cin>>n>>m>>k; for(long long i=2;i<=n;i++) { long long p; cin>>p; v[p].push_back(i); } for(long long i=1;i<=m;i++) { long long x; cin>>x; cin>>d[x]>>w[x]; } } set<long long> s[100001]; unordered_map<long long,long long> mp[100001]; void dfs(long long i) { //cout<<i<<endl; for(long long j=0;j<v[i].size();j++) { long long nb=v[i][j]; dfs(nb); if(s[i].size()<s[nb].size()) { swap(s[i],s[nb]); swap(mp[i],mp[nb]); } for(auto it=s[nb].begin();it!=s[nb].end();it++) { long long c=*it; s[i].insert(c); mp[i][c]+=mp[nb][c]; } } long long rem=w[i]; auto it=s[i].upper_bound(d[i]); vector<int> h; while(rem&&it!=s[i].end()) { long long in=min(rem,mp[i][*it]); mp[i][*it]-=in; rem-=in; it++; if(mp[i][*it]==0)h.push_back(*it); } for(int j=0;j<h.size();j++) s[i].erase(h[j]); if(d[i])s[i].insert(d[i]); mp[i][d[i]]+=w[i]; /*cout<<"! "<<i<<endl; for(auto it=s[i].begin();it!=s[i].end();it++) cout<<*it<<" "<<mp[i][*it]<<endl;*/ } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); read(); dfs(1); long long ans=0; for(auto it=s[1].begin();it!=s[1].end();it++) ans+=mp[1][*it]; cout<<ans<<endl; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 12880 KB | Output is correct |
2 | Correct | 3 ms | 12880 KB | Output is correct |
3 | Correct | 3 ms | 12880 KB | Output is correct |
4 | Correct | 3 ms | 12880 KB | Output is correct |
5 | Correct | 3 ms | 13048 KB | Output is correct |
6 | Correct | 3 ms | 12880 KB | Output is correct |
7 | Correct | 3 ms | 12880 KB | Output is correct |
8 | Correct | 4 ms | 12880 KB | Output is correct |
9 | Correct | 3 ms | 12880 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 112 ms | 36904 KB | Output is correct |
2 | Correct | 61 ms | 31048 KB | Output is correct |
3 | Correct | 236 ms | 63848 KB | Output is correct |
4 | Correct | 91 ms | 40900 KB | Output is correct |
5 | Correct | 155 ms | 42084 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 13136 KB | Output is correct |
2 | Correct | 3 ms | 13136 KB | Output is correct |
3 | Correct | 3 ms | 13136 KB | Output is correct |
4 | Correct | 58 ms | 41204 KB | Output is correct |
5 | Correct | 80 ms | 45400 KB | Output is correct |
6 | Correct | 88 ms | 42584 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 73 ms | 27076 KB | Output is correct |
2 | Correct | 72 ms | 25960 KB | Output is correct |
3 | Correct | 50 ms | 28744 KB | Output is correct |
4 | Correct | 44 ms | 33484 KB | Output is correct |
5 | Correct | 47 ms | 37960 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 12880 KB | Output is correct |
2 | Correct | 3 ms | 12880 KB | Output is correct |
3 | Correct | 3 ms | 12880 KB | Output is correct |
4 | Correct | 3 ms | 12880 KB | Output is correct |
5 | Correct | 3 ms | 13048 KB | Output is correct |
6 | Correct | 3 ms | 12880 KB | Output is correct |
7 | Correct | 3 ms | 12880 KB | Output is correct |
8 | Correct | 4 ms | 12880 KB | Output is correct |
9 | Correct | 3 ms | 12880 KB | Output is correct |
10 | Correct | 91 ms | 32584 KB | Output is correct |
11 | Correct | 100 ms | 30752 KB | Output is correct |
12 | Correct | 52 ms | 28760 KB | Output is correct |
13 | Correct | 43 ms | 33476 KB | Output is correct |
14 | Correct | 46 ms | 37960 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 16464 KB | Output is correct |
2 | Correct | 57 ms | 30168 KB | Output is correct |
3 | Correct | 51 ms | 30024 KB | Output is correct |
4 | Correct | 75 ms | 30024 KB | Output is correct |
5 | Correct | 42 ms | 29396 KB | Output is correct |
6 | Correct | 61 ms | 28824 KB | Output is correct |
7 | Correct | 37 ms | 27976 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 12880 KB | Output is correct |
2 | Correct | 3 ms | 12880 KB | Output is correct |
3 | Correct | 3 ms | 12880 KB | Output is correct |
4 | Correct | 3 ms | 12880 KB | Output is correct |
5 | Correct | 3 ms | 13048 KB | Output is correct |
6 | Correct | 3 ms | 12880 KB | Output is correct |
7 | Correct | 3 ms | 12880 KB | Output is correct |
8 | Correct | 4 ms | 12880 KB | Output is correct |
9 | Correct | 3 ms | 12880 KB | Output is correct |
10 | Correct | 3 ms | 13136 KB | Output is correct |
11 | Correct | 3 ms | 13136 KB | Output is correct |
12 | Correct | 3 ms | 13136 KB | Output is correct |
13 | Correct | 58 ms | 41204 KB | Output is correct |
14 | Correct | 80 ms | 45400 KB | Output is correct |
15 | Correct | 88 ms | 42584 KB | Output is correct |
16 | Correct | 91 ms | 32584 KB | Output is correct |
17 | Correct | 100 ms | 30752 KB | Output is correct |
18 | Correct | 52 ms | 28760 KB | Output is correct |
19 | Correct | 43 ms | 33476 KB | Output is correct |
20 | Correct | 46 ms | 37960 KB | Output is correct |
21 | Correct | 29 ms | 19732 KB | Output is correct |
22 | Correct | 115 ms | 39056 KB | Output is correct |
23 | Correct | 146 ms | 44708 KB | Output is correct |
24 | Correct | 214 ms | 59224 KB | Output is correct |
25 | Correct | 98 ms | 40256 KB | Output is correct |
26 | Correct | 134 ms | 40400 KB | Output is correct |
27 | Correct | 114 ms | 36004 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 12880 KB | Output is correct |
2 | Correct | 3 ms | 12880 KB | Output is correct |
3 | Correct | 3 ms | 12880 KB | Output is correct |
4 | Correct | 3 ms | 12880 KB | Output is correct |
5 | Correct | 3 ms | 13048 KB | Output is correct |
6 | Correct | 3 ms | 12880 KB | Output is correct |
7 | Correct | 3 ms | 12880 KB | Output is correct |
8 | Correct | 4 ms | 12880 KB | Output is correct |
9 | Correct | 3 ms | 12880 KB | Output is correct |
10 | Correct | 112 ms | 36904 KB | Output is correct |
11 | Correct | 61 ms | 31048 KB | Output is correct |
12 | Correct | 236 ms | 63848 KB | Output is correct |
13 | Correct | 91 ms | 40900 KB | Output is correct |
14 | Correct | 155 ms | 42084 KB | Output is correct |
15 | Correct | 3 ms | 13136 KB | Output is correct |
16 | Correct | 3 ms | 13136 KB | Output is correct |
17 | Correct | 3 ms | 13136 KB | Output is correct |
18 | Correct | 58 ms | 41204 KB | Output is correct |
19 | Correct | 80 ms | 45400 KB | Output is correct |
20 | Correct | 88 ms | 42584 KB | Output is correct |
21 | Correct | 73 ms | 27076 KB | Output is correct |
22 | Correct | 72 ms | 25960 KB | Output is correct |
23 | Correct | 50 ms | 28744 KB | Output is correct |
24 | Correct | 44 ms | 33484 KB | Output is correct |
25 | Correct | 47 ms | 37960 KB | Output is correct |
26 | Correct | 91 ms | 32584 KB | Output is correct |
27 | Correct | 100 ms | 30752 KB | Output is correct |
28 | Correct | 52 ms | 28760 KB | Output is correct |
29 | Correct | 43 ms | 33476 KB | Output is correct |
30 | Correct | 46 ms | 37960 KB | Output is correct |
31 | Correct | 9 ms | 16464 KB | Output is correct |
32 | Correct | 57 ms | 30168 KB | Output is correct |
33 | Correct | 51 ms | 30024 KB | Output is correct |
34 | Correct | 75 ms | 30024 KB | Output is correct |
35 | Correct | 42 ms | 29396 KB | Output is correct |
36 | Correct | 61 ms | 28824 KB | Output is correct |
37 | Correct | 37 ms | 27976 KB | Output is correct |
38 | Correct | 29 ms | 19732 KB | Output is correct |
39 | Correct | 115 ms | 39056 KB | Output is correct |
40 | Correct | 146 ms | 44708 KB | Output is correct |
41 | Correct | 214 ms | 59224 KB | Output is correct |
42 | Correct | 98 ms | 40256 KB | Output is correct |
43 | Correct | 134 ms | 40400 KB | Output is correct |
44 | Correct | 114 ms | 36004 KB | Output is correct |
45 | Correct | 32 ms | 19792 KB | Output is correct |
46 | Correct | 125 ms | 39200 KB | Output is correct |
47 | Correct | 174 ms | 44964 KB | Output is correct |
48 | Correct | 246 ms | 59684 KB | Output is correct |
49 | Correct | 132 ms | 40928 KB | Output is correct |
50 | Correct | 161 ms | 41304 KB | Output is correct |
51 | Correct | 120 ms | 36516 KB | Output is correct |