# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199996 | 2020-02-04T17:18:40 Z | davitmarg | Magic Tree (CEOI19_magictree) | C++17 | 198 ms | 31224 KB |
/*DavitMarg*/ #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <cstring> #include <map> #include <set> #include <queue> #include <iomanip> #include <stack> #include <cassert> #include <iterator> #include <bitset> #include <fstream> #define mod 998244353ll #define LL long long #define LD long double #define MP make_pair #define PB push_back #define all(v) v.begin(),v.end() using namespace std; int n,m,K,d[100005]; LL w[100005],ans; vector<int> g[100005]; multiset<pair<int,LL>> s[100005]; void dfs(int v) { for(int i=0;i<g[v].size();i++) { int to=g[v][i]; dfs(to); if(s[to].size()>s[v].size()) swap(s[to],s[v]); while(!s[to].empty()) { s[v].insert((*s[to].begin())); s[to].erase(s[to].begin()); } } if(!w[v]) return; LL cnt=w[v]; while(s[v].upper_bound(MP(d[v],mod*mod))!=s[v].end() && cnt) { auto it=s[v].upper_bound(MP(d[v],mod*mod)); pair<int,LL> x=(*it); s[v].erase(it); LL d=min(x.second,cnt); cnt-=d; x.second-=d; if(x.second) s[v].insert(x); } s[v].insert(MP(d[v],w[v])); } int main() { cin>>n>>m>>K; for(int i=2;i<=n;i++) { int p; scanf("%d",&p); g[p].PB(i); } for(int i=1;i<=m;i++) { int v; scanf("%d",&v); scanf("%d%lld",d+v,w+v); } dfs(1); for(auto it=s[1].begin();it!=s[1].end();++it) ans+=(*it).second; cout<<ans<<endl; return 0; } /* */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 7416 KB | Output is correct |
2 | Correct | 9 ms | 7416 KB | Output is correct |
3 | Correct | 9 ms | 7420 KB | Output is correct |
4 | Correct | 11 ms | 7416 KB | Output is correct |
5 | Correct | 9 ms | 7288 KB | Output is correct |
6 | Correct | 9 ms | 7416 KB | Output is correct |
7 | Correct | 9 ms | 7416 KB | Output is correct |
8 | Correct | 9 ms | 7416 KB | Output is correct |
9 | Correct | 9 ms | 7416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 80 ms | 12280 KB | Output is correct |
2 | Correct | 63 ms | 17144 KB | Output is correct |
3 | Correct | 187 ms | 15840 KB | Output is correct |
4 | Correct | 110 ms | 15476 KB | Output is correct |
5 | Correct | 159 ms | 16888 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 7544 KB | Output is correct |
2 | Correct | 10 ms | 7544 KB | Output is correct |
3 | Correct | 10 ms | 7544 KB | Output is correct |
4 | Correct | 86 ms | 24952 KB | Output is correct |
5 | Correct | 125 ms | 31224 KB | Output is correct |
6 | Correct | 104 ms | 24952 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 196 ms | 15576 KB | Output is correct |
2 | Correct | 198 ms | 16632 KB | Output is correct |
3 | Correct | 129 ms | 19960 KB | Output is correct |
4 | Correct | 122 ms | 15268 KB | Output is correct |
5 | Correct | 115 ms | 27768 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 7416 KB | Output is correct |
2 | Correct | 9 ms | 7416 KB | Output is correct |
3 | Correct | 9 ms | 7420 KB | Output is correct |
4 | Correct | 11 ms | 7416 KB | Output is correct |
5 | Correct | 9 ms | 7288 KB | Output is correct |
6 | Correct | 9 ms | 7416 KB | Output is correct |
7 | Correct | 9 ms | 7416 KB | Output is correct |
8 | Correct | 9 ms | 7416 KB | Output is correct |
9 | Correct | 9 ms | 7416 KB | Output is correct |
10 | Correct | 148 ms | 14840 KB | Output is correct |
11 | Correct | 146 ms | 14840 KB | Output is correct |
12 | Correct | 111 ms | 18168 KB | Output is correct |
13 | Correct | 98 ms | 15392 KB | Output is correct |
14 | Correct | 98 ms | 25208 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 8056 KB | Output is correct |
2 | Correct | 47 ms | 10744 KB | Output is correct |
3 | Correct | 48 ms | 10744 KB | Output is correct |
4 | Correct | 52 ms | 10872 KB | Output is correct |
5 | Correct | 21 ms | 9328 KB | Output is correct |
6 | Correct | 44 ms | 13048 KB | Output is correct |
7 | Correct | 47 ms | 16632 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 7416 KB | Output is correct |
2 | Correct | 9 ms | 7416 KB | Output is correct |
3 | Correct | 9 ms | 7420 KB | Output is correct |
4 | Correct | 11 ms | 7416 KB | Output is correct |
5 | Correct | 9 ms | 7288 KB | Output is correct |
6 | Correct | 9 ms | 7416 KB | Output is correct |
7 | Correct | 9 ms | 7416 KB | Output is correct |
8 | Correct | 9 ms | 7416 KB | Output is correct |
9 | Correct | 9 ms | 7416 KB | Output is correct |
10 | Correct | 10 ms | 7544 KB | Output is correct |
11 | Correct | 10 ms | 7544 KB | Output is correct |
12 | Correct | 10 ms | 7544 KB | Output is correct |
13 | Correct | 86 ms | 24952 KB | Output is correct |
14 | Correct | 125 ms | 31224 KB | Output is correct |
15 | Correct | 104 ms | 24952 KB | Output is correct |
16 | Correct | 148 ms | 14840 KB | Output is correct |
17 | Correct | 146 ms | 14840 KB | Output is correct |
18 | Correct | 111 ms | 18168 KB | Output is correct |
19 | Correct | 98 ms | 15392 KB | Output is correct |
20 | Correct | 98 ms | 25208 KB | Output is correct |
21 | Correct | 32 ms | 8952 KB | Output is correct |
22 | Correct | 109 ms | 13176 KB | Output is correct |
23 | Correct | 115 ms | 13176 KB | Output is correct |
24 | Correct | 168 ms | 14712 KB | Output is correct |
25 | Correct | 115 ms | 15344 KB | Output is correct |
26 | Correct | 149 ms | 16592 KB | Output is correct |
27 | Correct | 128 ms | 17912 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 7416 KB | Output is correct |
2 | Correct | 9 ms | 7416 KB | Output is correct |
3 | Correct | 9 ms | 7420 KB | Output is correct |
4 | Correct | 11 ms | 7416 KB | Output is correct |
5 | Correct | 9 ms | 7288 KB | Output is correct |
6 | Correct | 9 ms | 7416 KB | Output is correct |
7 | Correct | 9 ms | 7416 KB | Output is correct |
8 | Correct | 9 ms | 7416 KB | Output is correct |
9 | Correct | 9 ms | 7416 KB | Output is correct |
10 | Correct | 80 ms | 12280 KB | Output is correct |
11 | Correct | 63 ms | 17144 KB | Output is correct |
12 | Correct | 187 ms | 15840 KB | Output is correct |
13 | Correct | 110 ms | 15476 KB | Output is correct |
14 | Correct | 159 ms | 16888 KB | Output is correct |
15 | Correct | 10 ms | 7544 KB | Output is correct |
16 | Correct | 10 ms | 7544 KB | Output is correct |
17 | Correct | 10 ms | 7544 KB | Output is correct |
18 | Correct | 86 ms | 24952 KB | Output is correct |
19 | Correct | 125 ms | 31224 KB | Output is correct |
20 | Correct | 104 ms | 24952 KB | Output is correct |
21 | Correct | 196 ms | 15576 KB | Output is correct |
22 | Correct | 198 ms | 16632 KB | Output is correct |
23 | Correct | 129 ms | 19960 KB | Output is correct |
24 | Correct | 122 ms | 15268 KB | Output is correct |
25 | Correct | 115 ms | 27768 KB | Output is correct |
26 | Correct | 148 ms | 14840 KB | Output is correct |
27 | Correct | 146 ms | 14840 KB | Output is correct |
28 | Correct | 111 ms | 18168 KB | Output is correct |
29 | Correct | 98 ms | 15392 KB | Output is correct |
30 | Correct | 98 ms | 25208 KB | Output is correct |
31 | Correct | 17 ms | 8056 KB | Output is correct |
32 | Correct | 47 ms | 10744 KB | Output is correct |
33 | Correct | 48 ms | 10744 KB | Output is correct |
34 | Correct | 52 ms | 10872 KB | Output is correct |
35 | Correct | 21 ms | 9328 KB | Output is correct |
36 | Correct | 44 ms | 13048 KB | Output is correct |
37 | Correct | 47 ms | 16632 KB | Output is correct |
38 | Correct | 32 ms | 8952 KB | Output is correct |
39 | Correct | 109 ms | 13176 KB | Output is correct |
40 | Correct | 115 ms | 13176 KB | Output is correct |
41 | Correct | 168 ms | 14712 KB | Output is correct |
42 | Correct | 115 ms | 15344 KB | Output is correct |
43 | Correct | 149 ms | 16592 KB | Output is correct |
44 | Correct | 128 ms | 17912 KB | Output is correct |
45 | Correct | 37 ms | 9208 KB | Output is correct |
46 | Correct | 129 ms | 13432 KB | Output is correct |
47 | Correct | 133 ms | 13388 KB | Output is correct |
48 | Correct | 196 ms | 15312 KB | Output is correct |
49 | Correct | 126 ms | 15376 KB | Output is correct |
50 | Correct | 159 ms | 16736 KB | Output is correct |
51 | Correct | 167 ms | 18032 KB | Output is correct |