# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1115888 | 2024-11-21T03:32:49 Z | guagua0407 | Magic Tree (CEOI19_magictree) | C++17 | 147 ms | 34120 KB |
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int dx[4]={0,0,1,-1}; int dy[4]={1,-1,0,0}; void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } const int mxn=1e5+5; vector<int> adj[mxn]; multiset<pair<int,int>> S[mxn]; int d[mxn]; int w[mxn]; void dfs(int v,int p=0){ for(auto u:adj[v]){ dfs(u,v); if(S[v].size()<S[u].size()){ swap(S[v],S[u]); } for(auto x:S[u]){ S[v].insert(x); } } auto it=S[v].lower_bound({d[v]+1,0}); int sum=0; while(it!=S[v].end() and sum+(*it).s<=w[v]){ sum+=(*it).s; it=S[v].erase(it); } if(it!=S[v].end()){ auto p=(*it); S[v].erase(it); p.s=sum+p.s-w[v]; S[v].insert(p); } S[v].insert({d[v],w[v]}); } signed main() {_ int n,m,k; cin>>n>>m>>k; for(int i=2;i<=n;i++){ int p; cin>>p; adj[p].push_back(i); } for(int i=0;i<m;i++){ int v; cin>>v; cin>>d[v]>>w[v]; } dfs(1); ll ans=0; for(auto v:S[1]){ ans+=v.s; } cout<<ans<<'\n'; return 0; } //maybe its multiset not set //yeeorz //diaoborz
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 8016 KB | Output is correct |
2 | Correct | 3 ms | 8184 KB | Output is correct |
3 | Correct | 3 ms | 8016 KB | Output is correct |
4 | Correct | 2 ms | 8016 KB | Output is correct |
5 | Correct | 3 ms | 8016 KB | Output is correct |
6 | Correct | 3 ms | 8016 KB | Output is correct |
7 | Correct | 2 ms | 8016 KB | Output is correct |
8 | Correct | 4 ms | 8016 KB | Output is correct |
9 | Correct | 3 ms | 8184 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 106 ms | 33992 KB | Output is correct |
2 | Correct | 60 ms | 22856 KB | Output is correct |
3 | Correct | 147 ms | 32020 KB | Output is correct |
4 | Correct | 67 ms | 17864 KB | Output is correct |
5 | Correct | 79 ms | 18760 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 8272 KB | Output is correct |
2 | Correct | 3 ms | 8272 KB | Output is correct |
3 | Correct | 3 ms | 8272 KB | Output is correct |
4 | Correct | 46 ms | 22344 KB | Output is correct |
5 | Correct | 62 ms | 26952 KB | Output is correct |
6 | Correct | 60 ms | 22352 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 110 ms | 30024 KB | Output is correct |
2 | Correct | 121 ms | 33864 KB | Output is correct |
3 | Correct | 71 ms | 20296 KB | Output is correct |
4 | Correct | 65 ms | 18028 KB | Output is correct |
5 | Correct | 74 ms | 24912 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 8016 KB | Output is correct |
2 | Correct | 3 ms | 8184 KB | Output is correct |
3 | Correct | 3 ms | 8016 KB | Output is correct |
4 | Correct | 2 ms | 8016 KB | Output is correct |
5 | Correct | 3 ms | 8016 KB | Output is correct |
6 | Correct | 3 ms | 8016 KB | Output is correct |
7 | Correct | 2 ms | 8016 KB | Output is correct |
8 | Correct | 4 ms | 8016 KB | Output is correct |
9 | Correct | 3 ms | 8184 KB | Output is correct |
10 | Correct | 82 ms | 27604 KB | Output is correct |
11 | Correct | 86 ms | 27984 KB | Output is correct |
12 | Correct | 66 ms | 18248 KB | Output is correct |
13 | Correct | 51 ms | 17872 KB | Output is correct |
14 | Correct | 58 ms | 22956 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 12624 KB | Output is correct |
2 | Correct | 86 ms | 34120 KB | Output is correct |
3 | Correct | 86 ms | 33352 KB | Output is correct |
4 | Correct | 82 ms | 33096 KB | Output is correct |
5 | Correct | 28 ms | 17872 KB | Output is correct |
6 | Correct | 49 ms | 21576 KB | Output is correct |
7 | Correct | 53 ms | 22856 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 8016 KB | Output is correct |
2 | Correct | 3 ms | 8184 KB | Output is correct |
3 | Correct | 3 ms | 8016 KB | Output is correct |
4 | Correct | 2 ms | 8016 KB | Output is correct |
5 | Correct | 3 ms | 8016 KB | Output is correct |
6 | Correct | 3 ms | 8016 KB | Output is correct |
7 | Correct | 2 ms | 8016 KB | Output is correct |
8 | Correct | 4 ms | 8016 KB | Output is correct |
9 | Correct | 3 ms | 8184 KB | Output is correct |
10 | Correct | 3 ms | 8272 KB | Output is correct |
11 | Correct | 3 ms | 8272 KB | Output is correct |
12 | Correct | 3 ms | 8272 KB | Output is correct |
13 | Correct | 46 ms | 22344 KB | Output is correct |
14 | Correct | 62 ms | 26952 KB | Output is correct |
15 | Correct | 60 ms | 22352 KB | Output is correct |
16 | Correct | 82 ms | 27604 KB | Output is correct |
17 | Correct | 86 ms | 27984 KB | Output is correct |
18 | Correct | 66 ms | 18248 KB | Output is correct |
19 | Correct | 51 ms | 17872 KB | Output is correct |
20 | Correct | 58 ms | 22956 KB | Output is correct |
21 | Correct | 23 ms | 11600 KB | Output is correct |
22 | Correct | 110 ms | 31572 KB | Output is correct |
23 | Correct | 101 ms | 31484 KB | Output is correct |
24 | Correct | 96 ms | 27204 KB | Output is correct |
25 | Correct | 58 ms | 17944 KB | Output is correct |
26 | Correct | 77 ms | 19108 KB | Output is correct |
27 | Correct | 75 ms | 18000 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 8016 KB | Output is correct |
2 | Correct | 3 ms | 8184 KB | Output is correct |
3 | Correct | 3 ms | 8016 KB | Output is correct |
4 | Correct | 2 ms | 8016 KB | Output is correct |
5 | Correct | 3 ms | 8016 KB | Output is correct |
6 | Correct | 3 ms | 8016 KB | Output is correct |
7 | Correct | 2 ms | 8016 KB | Output is correct |
8 | Correct | 4 ms | 8016 KB | Output is correct |
9 | Correct | 3 ms | 8184 KB | Output is correct |
10 | Correct | 106 ms | 33992 KB | Output is correct |
11 | Correct | 60 ms | 22856 KB | Output is correct |
12 | Correct | 147 ms | 32020 KB | Output is correct |
13 | Correct | 67 ms | 17864 KB | Output is correct |
14 | Correct | 79 ms | 18760 KB | Output is correct |
15 | Correct | 3 ms | 8272 KB | Output is correct |
16 | Correct | 3 ms | 8272 KB | Output is correct |
17 | Correct | 3 ms | 8272 KB | Output is correct |
18 | Correct | 46 ms | 22344 KB | Output is correct |
19 | Correct | 62 ms | 26952 KB | Output is correct |
20 | Correct | 60 ms | 22352 KB | Output is correct |
21 | Correct | 110 ms | 30024 KB | Output is correct |
22 | Correct | 121 ms | 33864 KB | Output is correct |
23 | Correct | 71 ms | 20296 KB | Output is correct |
24 | Correct | 65 ms | 18028 KB | Output is correct |
25 | Correct | 74 ms | 24912 KB | Output is correct |
26 | Correct | 82 ms | 27604 KB | Output is correct |
27 | Correct | 86 ms | 27984 KB | Output is correct |
28 | Correct | 66 ms | 18248 KB | Output is correct |
29 | Correct | 51 ms | 17872 KB | Output is correct |
30 | Correct | 58 ms | 22956 KB | Output is correct |
31 | Correct | 14 ms | 12624 KB | Output is correct |
32 | Correct | 86 ms | 34120 KB | Output is correct |
33 | Correct | 86 ms | 33352 KB | Output is correct |
34 | Correct | 82 ms | 33096 KB | Output is correct |
35 | Correct | 28 ms | 17872 KB | Output is correct |
36 | Correct | 49 ms | 21576 KB | Output is correct |
37 | Correct | 53 ms | 22856 KB | Output is correct |
38 | Correct | 23 ms | 11600 KB | Output is correct |
39 | Correct | 110 ms | 31572 KB | Output is correct |
40 | Correct | 101 ms | 31484 KB | Output is correct |
41 | Correct | 96 ms | 27204 KB | Output is correct |
42 | Correct | 58 ms | 17944 KB | Output is correct |
43 | Correct | 77 ms | 19108 KB | Output is correct |
44 | Correct | 75 ms | 18000 KB | Output is correct |
45 | Correct | 18 ms | 11856 KB | Output is correct |
46 | Correct | 105 ms | 32584 KB | Output is correct |
47 | Correct | 106 ms | 31816 KB | Output is correct |
48 | Correct | 102 ms | 29356 KB | Output is correct |
49 | Correct | 65 ms | 17864 KB | Output is correct |
50 | Correct | 86 ms | 19364 KB | Output is correct |
51 | Correct | 73 ms | 18248 KB | Output is correct |