# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
531697 | Yazan_Alattar | Magic Tree (CEOI19_magictree) | C++14 | 2093 ms | 797812 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>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 100007;
const ll inf = 1e18;
const ll mod = 998244353;
const double pi = acos(-1);
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;
vector <int> adj[M];
int n, m, k, ripe[M], w[M], vert[M];
ll dp[M][1007];
void dfs(int node){
for(auto i : adj[node]){
dfs(i);
for(int j = 1; j <= k; ++j) dp[node][j] += dp[i][j];
}
dp[node][ripe[node]] += w[node];
for(int i = 1; i <= k; ++i) dp[node][i] = max(dp[node][i], dp[node][i - 1]);
return;
}
int main(){
scanf("%d%d%d", &n, &m, &k); k = min(k, m);
for(int i = 2; i <= n; ++i){
int p; scanf("%d", &p);
adj[p].pb(i);
}
vector <int> v;
for(int i = 1; i <= m; ++i){
scanf("%d", &vert[i]);
scanf("%d%d", &ripe[vert[i]], &w[vert[i]]);
v.pb(ripe[vert[i]]);
}
sort(all(v));
v.erase(unique(all(v)), v.end());
for(int i = 1; i <= m; ++i)
for(int j = 0; j < (int)v.size(); ++j)
if(v[j] == ripe[vert[i]]){ripe[vert[i]] = j + 1; break;}
dfs(1);
printf("%lld\n", dp[1][k]);
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... |