# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
229388 | 2020-05-04T11:11:30 Z | Ruxandra985 | Magic Tree (CEOI19_magictree) | C++14 | 187 ms | 36984 KB |
#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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7424 KB | Output is correct |
2 | Correct | 9 ms | 7424 KB | Output is correct |
3 | Correct | 9 ms | 7296 KB | Output is correct |
4 | Correct | 9 ms | 7424 KB | Output is correct |
5 | Correct | 9 ms | 7424 KB | Output is correct |
6 | Correct | 10 ms | 7424 KB | Output is correct |
7 | Correct | 9 ms | 7424 KB | Output is correct |
8 | Correct | 9 ms | 7424 KB | Output is correct |
9 | Correct | 8 ms | 7424 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 85 ms | 18424 KB | Output is correct |
2 | Correct | 62 ms | 19064 KB | Output is correct |
3 | Correct | 170 ms | 36984 KB | Output is correct |
4 | Correct | 114 ms | 20080 KB | Output is correct |
5 | Correct | 148 ms | 21752 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 7552 KB | Output is correct |
2 | Correct | 9 ms | 7552 KB | Output is correct |
3 | Correct | 9 ms | 7552 KB | Output is correct |
4 | Correct | 80 ms | 25720 KB | Output is correct |
5 | Correct | 105 ms | 29688 KB | Output is correct |
6 | Correct | 105 ms | 25724 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 106 ms | 15556 KB | Output is correct |
2 | Correct | 112 ms | 14792 KB | Output is correct |
3 | Correct | 99 ms | 18936 KB | Output is correct |
4 | Correct | 68 ms | 15984 KB | Output is correct |
5 | Correct | 76 ms | 25976 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7424 KB | Output is correct |
2 | Correct | 9 ms | 7424 KB | Output is correct |
3 | Correct | 9 ms | 7296 KB | Output is correct |
4 | Correct | 9 ms | 7424 KB | Output is correct |
5 | Correct | 9 ms | 7424 KB | Output is correct |
6 | Correct | 10 ms | 7424 KB | Output is correct |
7 | Correct | 9 ms | 7424 KB | Output is correct |
8 | Correct | 9 ms | 7424 KB | Output is correct |
9 | Correct | 8 ms | 7424 KB | Output is correct |
10 | Correct | 110 ms | 18936 KB | Output is correct |
11 | Correct | 113 ms | 17656 KB | Output is correct |
12 | Correct | 82 ms | 18232 KB | Output is correct |
13 | Correct | 60 ms | 15344 KB | Output is correct |
14 | Correct | 70 ms | 25336 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 8192 KB | Output is correct |
2 | Correct | 44 ms | 10496 KB | Output is correct |
3 | Correct | 49 ms | 10488 KB | Output is correct |
4 | Correct | 45 ms | 10488 KB | Output is correct |
5 | Correct | 22 ms | 8952 KB | Output is correct |
6 | Correct | 45 ms | 12672 KB | Output is correct |
7 | Correct | 44 ms | 16256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7424 KB | Output is correct |
2 | Correct | 9 ms | 7424 KB | Output is correct |
3 | Correct | 9 ms | 7296 KB | Output is correct |
4 | Correct | 9 ms | 7424 KB | Output is correct |
5 | Correct | 9 ms | 7424 KB | Output is correct |
6 | Correct | 10 ms | 7424 KB | Output is correct |
7 | Correct | 9 ms | 7424 KB | Output is correct |
8 | Correct | 9 ms | 7424 KB | Output is correct |
9 | Correct | 8 ms | 7424 KB | Output is correct |
10 | Correct | 9 ms | 7552 KB | Output is correct |
11 | Correct | 9 ms | 7552 KB | Output is correct |
12 | Correct | 9 ms | 7552 KB | Output is correct |
13 | Correct | 80 ms | 25720 KB | Output is correct |
14 | Correct | 105 ms | 29688 KB | Output is correct |
15 | Correct | 105 ms | 25724 KB | Output is correct |
16 | Correct | 110 ms | 18936 KB | Output is correct |
17 | Correct | 113 ms | 17656 KB | Output is correct |
18 | Correct | 82 ms | 18232 KB | Output is correct |
19 | Correct | 60 ms | 15344 KB | Output is correct |
20 | Correct | 70 ms | 25336 KB | Output is correct |
21 | Correct | 34 ms | 11512 KB | Output is correct |
22 | Correct | 108 ms | 20472 KB | Output is correct |
23 | Correct | 115 ms | 24696 KB | Output is correct |
24 | Correct | 187 ms | 36344 KB | Output is correct |
25 | Correct | 126 ms | 19304 KB | Output is correct |
26 | Correct | 142 ms | 22008 KB | Output is correct |
27 | Correct | 121 ms | 20984 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7424 KB | Output is correct |
2 | Correct | 9 ms | 7424 KB | Output is correct |
3 | Correct | 9 ms | 7296 KB | Output is correct |
4 | Correct | 9 ms | 7424 KB | Output is correct |
5 | Correct | 9 ms | 7424 KB | Output is correct |
6 | Correct | 10 ms | 7424 KB | Output is correct |
7 | Correct | 9 ms | 7424 KB | Output is correct |
8 | Correct | 9 ms | 7424 KB | Output is correct |
9 | Correct | 8 ms | 7424 KB | Output is correct |
10 | Correct | 85 ms | 18424 KB | Output is correct |
11 | Correct | 62 ms | 19064 KB | Output is correct |
12 | Correct | 170 ms | 36984 KB | Output is correct |
13 | Correct | 114 ms | 20080 KB | Output is correct |
14 | Correct | 148 ms | 21752 KB | Output is correct |
15 | Correct | 9 ms | 7552 KB | Output is correct |
16 | Correct | 9 ms | 7552 KB | Output is correct |
17 | Correct | 9 ms | 7552 KB | Output is correct |
18 | Correct | 80 ms | 25720 KB | Output is correct |
19 | Correct | 105 ms | 29688 KB | Output is correct |
20 | Correct | 105 ms | 25724 KB | Output is correct |
21 | Correct | 106 ms | 15556 KB | Output is correct |
22 | Correct | 112 ms | 14792 KB | Output is correct |
23 | Correct | 99 ms | 18936 KB | Output is correct |
24 | Correct | 68 ms | 15984 KB | Output is correct |
25 | Correct | 76 ms | 25976 KB | Output is correct |
26 | Correct | 110 ms | 18936 KB | Output is correct |
27 | Correct | 113 ms | 17656 KB | Output is correct |
28 | Correct | 82 ms | 18232 KB | Output is correct |
29 | Correct | 60 ms | 15344 KB | Output is correct |
30 | Correct | 70 ms | 25336 KB | Output is correct |
31 | Correct | 17 ms | 8192 KB | Output is correct |
32 | Correct | 44 ms | 10496 KB | Output is correct |
33 | Correct | 49 ms | 10488 KB | Output is correct |
34 | Correct | 45 ms | 10488 KB | Output is correct |
35 | Correct | 22 ms | 8952 KB | Output is correct |
36 | Correct | 45 ms | 12672 KB | Output is correct |
37 | Correct | 44 ms | 16256 KB | Output is correct |
38 | Correct | 34 ms | 11512 KB | Output is correct |
39 | Correct | 108 ms | 20472 KB | Output is correct |
40 | Correct | 115 ms | 24696 KB | Output is correct |
41 | Correct | 187 ms | 36344 KB | Output is correct |
42 | Correct | 126 ms | 19304 KB | Output is correct |
43 | Correct | 142 ms | 22008 KB | Output is correct |
44 | Correct | 121 ms | 20984 KB | Output is correct |
45 | Correct | 33 ms | 11264 KB | Output is correct |
46 | Correct | 115 ms | 19844 KB | Output is correct |
47 | Correct | 125 ms | 23288 KB | Output is correct |
48 | Correct | 186 ms | 33400 KB | Output is correct |
49 | Correct | 120 ms | 19952 KB | Output is correct |
50 | Correct | 143 ms | 22136 KB | Output is correct |
51 | Correct | 127 ms | 20984 KB | Output is correct |