# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
229388 | Ruxandra985 | Magic Tree (CEOI19_magictree) | C++14 | 187 ms | 36984 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define DIMN 100010
using namespace std;
map <int , long long> dp[DIMN] , aux;
vector <int> v[DIMN];
pair <int,int> fruits[DIMN];
int under[DIMN];
map <int , long long> :: iterator it , it2;
map <int , long long> :: reverse_iterator itt;
void dfs (int nod){
int vecin , mom , i;
long long val , win;
for (i = 0 ; i < v[nod].size() ; i++){
vecin = v[nod][i];
dfs (vecin);
if (dp[nod].size() < dp[vecin].size()){
swap(dp[nod] , dp[vecin]);
}
/// dp[nod] e mereu mai mare ca sa parcurg mereu ceva cat mai mic
for (it = dp[vecin].begin() ; it != dp[vecin].end() ; it++){
mom = it->first;
val = it->second;
dp[nod][mom] += val;
}
}
/// momentan dp[nod] e un fel de vector de frecventa
if (fruits[nod].first){
/// nod are un fruct, vreau sa vad daca e worth it sa il bag
dp[nod][fruits[nod].first] += fruits[nod].second;
/// daca as lua fructul , nu as mai putea sa iau nimic mai mare din fii
win = fruits[nod].second;
while (win > 0){
it = dp[nod].upper_bound(fruits[nod].first);
if (it == dp[nod].end())
break;
mom = it->first;
val = it->second;
/// mom > it
/// daca aleg sa iau fructul, e clar ca va trebui sa renunt la it
win = win - val;
if (win > 0){ /// am renuntat si oricum castig ceva
dp[nod].erase(it);
}
else { /// nu mai am niciun avantaj in mom asta
it->second = -win;
}
}
}
}
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int n , m , k , i , tt , nod , mom , val;
long long sol;
fscanf (fin,"%d%d%d",&n,&m,&k);
for (i = 2 ; i <= n ; i++){
fscanf (fin,"%d",&tt);
v[tt].push_back(i);
}
for (i = 1 ; i <= m ; i++){
fscanf (fin,"%d%d%d",&nod,&mom,&val);
fruits[nod] = make_pair(mom , val);
}
dfs(1);
sol = 0;
for (it = dp[1].begin() ; it != dp[1].end() ; it++){
sol += it->second;
}
fprintf (fout,"%lld" , sol);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |