Submission #236115

#TimeUsernameProblemLanguageResultExecution timeMemory
236115HeheheMagic Tree (CEOI19_magictree)C++14
3 / 100
73 ms13432 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define all(a) (a).begin(), (a).end() #define ff first #define ss second #define pb push_back #define mp make_pair #define rc(s) return cout<<s,0 #define pi pair <int, int> #define sz(x) (int)((x).size()) #define int long long const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; const ll inf = 0x3f3f3f3f3f3f3f; const ll mod = 1e9 + 7; const int N = 2e5 + 11; const int INF = 2e9; const ll INF64 = 3e18 + 1; const double lil = 0.0000000000001; //ifstream cin ("test.in"); //ofstream cout ("test.out"); int n, m, day[N], dp[N], val[N], k; vector<int>v[N]; void dfs(int nod){ if(sz(v[nod]) == 0){ dp[nod] = val[nod]; return; } for(auto it : v[nod]){ dfs(it); } int small = 0, big = 0, mxbig = 0, mxsmall = 0; for(auto it : v[nod]){ if(day[it] > day[nod]){ big += dp[it]; mxbig = max(mxbig, day[it]); }else{ small += dp[it]; mxsmall = max(mxsmall, day[it]); } } if(val[nod] == big){ day[nod] = max(mxsmall, min(day[nod], mxbig)); dp[nod] = big + small; }else if(val[nod] < big){ day[nod] = max(mxsmall, mxbig); dp[nod] = big + small; }else{ day[nod] = max(mxsmall, day[nod]); dp[nod] = val[nod] + small; } } int32_t main(){ ios_base :: sync_with_stdio(0); cin.tie(); cout.tie(); cin >> n >> m >> k; for(int i = 2, x; i <= n; i++){ cin >> x; v[x].pb(i); } for(int i = 1, p, d, x; i <= m; i++){ cin >> p >> d >> x; val[p] = x; day[p] = d; } dfs(1); rc(dp[1]); //for(int i = 1; i <= n; i++)cout << dp[i] << ' '; cout << '\n'; }
#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...