# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1116023 | 2024-11-21T07:54:18 Z | simona1230 | Magic Tree (CEOI19_magictree) | C++17 | 2000 ms | 1048576 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); 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 | 3 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 | 4 ms | 12880 KB | Output is correct |
5 | Correct | 3 ms | 12880 KB | Output is correct |
6 | Correct | 3 ms | 12880 KB | Output is correct |
7 | Correct | 3 ms | 12880 KB | Output is correct |
8 | Correct | 3 ms | 12880 KB | Output is correct |
9 | Correct | 3 ms | 12880 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 182 ms | 54944 KB | Output is correct |
2 | Execution timed out | 2140 ms | 972988 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 13648 KB | Output is correct |
2 | Correct | 12 ms | 17488 KB | Output is correct |
3 | Correct | 47 ms | 30988 KB | Output is correct |
4 | Correct | 192 ms | 98888 KB | Output is correct |
5 | Runtime error | 1908 ms | 1048576 KB | Execution killed with signal 9 |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 125 ms | 37708 KB | Output is correct |
2 | Correct | 100 ms | 36424 KB | Output is correct |
3 | Correct | 101 ms | 49992 KB | Output is correct |
4 | Correct | 50 ms | 34756 KB | Output is correct |
5 | Correct | 111 ms | 61768 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 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 | 4 ms | 12880 KB | Output is correct |
5 | Correct | 3 ms | 12880 KB | Output is correct |
6 | Correct | 3 ms | 12880 KB | Output is correct |
7 | Correct | 3 ms | 12880 KB | Output is correct |
8 | Correct | 3 ms | 12880 KB | Output is correct |
9 | Correct | 3 ms | 12880 KB | Output is correct |
10 | Correct | 184 ms | 52040 KB | Output is correct |
11 | Correct | 140 ms | 47432 KB | Output is correct |
12 | Correct | 402 ms | 169824 KB | Output is correct |
13 | Correct | 51 ms | 33988 KB | Output is correct |
14 | Correct | 390 ms | 209764 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 16976 KB | Output is correct |
2 | Correct | 51 ms | 31560 KB | Output is correct |
3 | Correct | 48 ms | 31580 KB | Output is correct |
4 | Correct | 74 ms | 31304 KB | Output is correct |
5 | Correct | 26 ms | 29644 KB | Output is correct |
6 | Correct | 1092 ms | 500328 KB | Output is correct |
7 | Correct | 1475 ms | 619816 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 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 | 4 ms | 12880 KB | Output is correct |
5 | Correct | 3 ms | 12880 KB | Output is correct |
6 | Correct | 3 ms | 12880 KB | Output is correct |
7 | Correct | 3 ms | 12880 KB | Output is correct |
8 | Correct | 3 ms | 12880 KB | Output is correct |
9 | Correct | 3 ms | 12880 KB | Output is correct |
10 | Correct | 5 ms | 13648 KB | Output is correct |
11 | Correct | 12 ms | 17488 KB | Output is correct |
12 | Correct | 47 ms | 30988 KB | Output is correct |
13 | Correct | 192 ms | 98888 KB | Output is correct |
14 | Runtime error | 1908 ms | 1048576 KB | Execution killed with signal 9 |
15 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 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 | 4 ms | 12880 KB | Output is correct |
5 | Correct | 3 ms | 12880 KB | Output is correct |
6 | Correct | 3 ms | 12880 KB | Output is correct |
7 | Correct | 3 ms | 12880 KB | Output is correct |
8 | Correct | 3 ms | 12880 KB | Output is correct |
9 | Correct | 3 ms | 12880 KB | Output is correct |
10 | Correct | 182 ms | 54944 KB | Output is correct |
11 | Execution timed out | 2140 ms | 972988 KB | Time limit exceeded |
12 | Halted | 0 ms | 0 KB | - |