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>
#include<fstream>
using namespace std;
ifstream fin("HCN.INP");
ofstream fout("HCN.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
//using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 1e9 + 9;
const int mxn = 1e5 + 5, mxq = 2e5 + 5, sq = 200, mxv = 2e6 + 5;
const ll inf = 1e17 + 5;
//const int base= (1 << 18);
int n, m, k;
vt<int>adj[mxn + 1];
int day[mxn + 1];
ll cost[mxn + 1], dp[mxn + 1], pre[mxn + 1];
void ckmax(ll &a, ll b){
a = max(a, b);
}
void dfs(int tme, int s){
dp[s] = pre[s];
ll tot = 0;
for(auto i: adj[s]){
dfs(tme, i);
tot += dp[i];
}
ckmax(dp[s], tot);
if(day[s] == tme)dp[s] += cost[s];
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> k;
for(int i = 2; i <= n; i++){
int p; cin >> p;
adj[p].pb(i);
}
vt<int>care;
for(int i = 0; i < m; i++){
int v; cin >> v;
cin >> day[v] >> cost[v];
care.pb(day[v]);
}
sort(care.begin(), care.end());
care.resize(unique(care.begin(), care.end()) - care.begin());
ll ans = 0;
for(int i = 0; i < sz(care); i++){
dfs(care[i], 1);
for(int j = 1; j <= n; j++){
ckmax(ans, dp[j]);
pre[j] = dp[j]; dp[j] = 0;
}
}
cout << ans;
return(0);
}
# | 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... |