Submission #855539

# Submission time Handle Problem Language Result Execution time Memory
855539 2023-10-01T11:56:35 Z mychecksedad Magic Tree (CEOI19_magictree) C++17
47 / 100
528 ms 811976 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 1e5+100, M = 1e5+10, K = 1e3+10;


int n, m, k, d[N];
vector<int> g[N];
double w[N], dp[N][K];
 
void dfs(int v){
  for(int i = 0; i < K; ++i) dp[v][i] = 0;
  for(int u: g[v]){
    dfs(u);
    for(int i = 1; i < K; ++i) dp[v][i] += dp[u][i];
  }
  dp[v][d[v]] += w[v];
  for(int i = 1; i < K; ++i) dp[v][i] = max(dp[v][i], dp[v][i - 1]);
}
 
 
void solve(){
  cin >> n >> m >> k;
  for(int i = 2; i <= n; ++i){
    int p; cin >> p;
    g[p].pb(i);
  }
  for(int i = 0; i <= n; ++i) d[i] = w[i] = 0;
  vector<int> val;
  for(int i = 0; i < m; ++i){
    int v, dd, e; cin >> v >> dd >> e;
    d[v] = dd;
    w[v] = e;
    val.pb(dd);
  }
  sort(all(val));
  val.erase(unique(all(val)), val.end());
  for(int i = 1; i <= n; ++i){
    if(d[i] > 0){
      d[i] = lower_bound(all(val), d[i]) - val.begin() + 1;
    }
  }


  dfs(1);


  cout << (ll)(*max_element(dp[1] + 1, dp[1] + K));
}
 


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  while(tt--){
    solve();
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 

Compilation message

magictree.cpp: In function 'int main()':
magictree.cpp:61:15: warning: unused variable 'aa' [-Wunused-variable]
   61 |   int tt = 1, aa;
      |               ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 519 ms 797952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 13148 KB Output is correct
2 Correct 6 ms 13332 KB Output is correct
3 Correct 6 ms 13148 KB Output is correct
4 Incorrect 496 ms 810120 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 523 ms 797644 KB Output is correct
2 Correct 526 ms 799560 KB Output is correct
3 Correct 528 ms 804780 KB Output is correct
4 Correct 453 ms 798140 KB Output is correct
5 Correct 491 ms 811976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
10 Correct 522 ms 797396 KB Output is correct
11 Correct 514 ms 797432 KB Output is correct
12 Correct 513 ms 802652 KB Output is correct
13 Correct 436 ms 796004 KB Output is correct
14 Correct 488 ms 809672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 163160 KB Output is correct
2 Correct 511 ms 797520 KB Output is correct
3 Correct 497 ms 797524 KB Output is correct
4 Correct 512 ms 797644 KB Output is correct
5 Correct 427 ms 796104 KB Output is correct
6 Correct 496 ms 799572 KB Output is correct
7 Correct 498 ms 802900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
10 Correct 5 ms 13148 KB Output is correct
11 Correct 6 ms 13332 KB Output is correct
12 Correct 6 ms 13148 KB Output is correct
13 Incorrect 496 ms 810120 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
10 Incorrect 519 ms 797952 KB Output isn't correct
11 Halted 0 ms 0 KB -