# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
607233 | 2022-07-26T13:43:04 Z | 1bin | Magic Tree (CEOI19_magictree) | C++14 | 131 ms | 36000 KB |
#include <bits/stdc++.h> using namespace std; #define all(v) v.begin(), v.end() typedef long long ll; const int NMAX = 1e5 + 5; ll n, m, k, a, b, c, p, d[NMAX], w[NMAX], ii[NMAX]; vector<int> adj[NMAX]; map<int, ll> mp[NMAX]; void merge(int a, int b){ if(mp[ii[a]].size() < mp[ii[b]].size()) swap(ii[a], ii[b]); for(auto&[x, y] : mp[ii[b]]) mp[ii[a]][x] += y; return; } void dfs(int x){ for(int & nx : adj[x]) { dfs(nx); merge(x, nx); } if(w[x]){ mp[ii[x]][d[x]] += w[x]; auto it = mp[ii[x]].upper_bound(d[x]); if(it != mp[ii[x]].end()) it->second -= w[x]; } return; } int main(void){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for(int i = 1; i <= n; i++) ii[i] = i; for(int i = 2; i <= n; i++){ cin >> p; adj[p].emplace_back(i); } while(m--){ cin >> a; cin >> d[a] >> w[a]; } dfs(1); ll ans = 0; for(auto& [x, y] : mp[ii[1]]) ans += y; cout << ans; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 7380 KB | Output is correct |
2 | Incorrect | 9 ms | 7380 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 63 ms | 18920 KB | Output is correct |
2 | Correct | 36 ms | 17612 KB | Output is correct |
3 | Correct | 131 ms | 36000 KB | Output is correct |
4 | Correct | 77 ms | 19452 KB | Output is correct |
5 | Correct | 115 ms | 20544 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 7508 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 64 ms | 15172 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 7380 KB | Output is correct |
2 | Incorrect | 9 ms | 7380 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 8276 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 7380 KB | Output is correct |
2 | Incorrect | 9 ms | 7380 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 7380 KB | Output is correct |
2 | Incorrect | 9 ms | 7380 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |