Submission #441055

#TimeUsernameProblemLanguageResultExecution timeMemory
441055hhhhauraMagic Tree (CEOI19_magictree)C++14
100 / 100
149 ms32072 KiB
#define wiwihorz #include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma loop-opt(on) #define rep(i, a, b) for(int i = a; i <= b; i++) #define rrep(i, a, b) for(int i = b; i >= a; i--) #define all(x) x.begin(), x.end() #define ceil(a, b) ((a + b - 1) / (b)) #define INF 1000000000000000000 #define MOD 998244353 #define eps (1e-9) using namespace std; #define int long long int #define lld long double #define pii pair<int, int> #define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()) #ifdef wiwihorz #define print(a...) kout("[" + string(#a) + "] = ", a) void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;} void kout() { cerr << endl; } template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); } #else #define print(...) 0 #define vprint(...) 0 #endif namespace solver { int n; vector<vector<int>> mp; vector<map<int, int>> s; vector<int> d, w; void init_(int _n) { n = _n; mp.assign(n + 1, vector<int>()); s.assign(n + 1, map<int, int>()); d.assign(n + 1, 0); w.assign(n + 1, 0); } void dfs(int x) { int id = 0; for(auto i : mp[x]) { dfs(i); if(s[i].size() > s[id].size()) id = i; } s[x].swap(s[id]); for(auto i : mp[x]) if(i != id) { for(auto j = s[i].begin(); j != s[i].end(); j = next(j)) { auto k = next(j); s[x][j->first] += j ->second; } s[i].clear(); } if(w[x]) { auto it = s[x].upper_bound(d[x]); int cur = 0; while(it != s[x].end()) { cur += it -> second; if(w[x] >= cur) { auto it1 = it; it = next(it); s[x].erase(it1); } else { s[x][it->first] = cur - w[x]; break; } } s[x][d[x]] += w[x]; } // print(x); // for(auto i : s[x]) print(i.first, i.second); return; } int solve() { dfs(1); int ans = 0; for(auto i : s[1]) { ans += i.second; } return ans; } }; using namespace solver; signed main() { ios::sync_with_stdio(false), cin.tie(0); int n, m, k; cin >> n >> m >> k; init_(n); rep(i, 2, n) { int x; cin >> x; mp[x].push_back(i); } rep(i, 1, m) { int a, b, c; cin >> a >> b >> c; w[a] = c, d[a] = b; } cout << solve() << "\n"; return 0; }

Compilation message (stderr)

magictree.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      | 
magictree.cpp:24:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |             ^~~~
magictree.cpp:24:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |                     ^~~~
magictree.cpp: In function 'void solver::dfs(long long int)':
magictree.cpp:52:10: warning: variable 'k' set but not used [-Wunused-but-set-variable]
   52 |     auto k = next(j);
      |          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...