Submission #470319

#TimeUsernameProblemLanguageResultExecution timeMemory
470319ymmFireworks (APIO16_fireworks)C++17
0 / 100
5 ms7364 KiB
/// /// ♪ Pizza mozzarella rella rella rella... ♪ /// #define _USE_MATH_DEFINES #define FAST ios::sync_with_stdio(false),cin.tie(0); #include <bits/stdc++.h> #define Loop(x, l, r) for(int x = (l); x < (r); ++x) #define LoopR(x, l, r) for(int x = (r)-1; x >= (l); --x) #define all(x) x.begin(), x.end() #define Kill(x) exit((cout << (x) << '\n', 0)) #define YN(flag) ((flag)? "YES": "NO") #define F first #define S second typedef long long ll; typedef unsigned long long ull; typedef std::pair<int,int> pii; typedef std::pair<ll ,ll > pll; using namespace std; const int N = 300'010; vector<pll> A[N]; int n, m; tuple<ll,ll,ll> dfs(int v) { if(v >= n) return {0,0,0}; ll x = 0, l = 0, r = 1e18; for(auto [u, w] : A[v]) { auto [x2, l2, r2] = dfs(u); l2 += w; r2 += w; if(l2 <= r && l <= r2) { l = max(l, l2); r = min(r, r2); x += x2; } else { auto tmp = l; l = min(r, r2); r = max(tmp, l2); x += x2; x += r-l; } } return {x,l,r}; } int main() { FAST; cin >> n >> m; Loop(i,1,n+m) { ll v, c; cin >> v >> c; --v; A[v].emplace_back(i,c); } cout << get<0>(dfs(0)); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...