Submission #855537

# Submission time Handle Problem Language Result Execution time Memory
855537 2023-10-01T11:55:36 Z mychecksedad Magic Tree (CEOI19_magictree) C++17
22 / 100
674 ms 811504 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 << *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 1 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 4796 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 674 ms 797924 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 13148 KB Output is correct
2 Correct 6 ms 13148 KB Output is correct
3 Correct 7 ms 13272 KB Output is correct
4 Incorrect 518 ms 811504 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 515 ms 799588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 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 4796 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 514 ms 798936 KB Output is correct
11 Correct 514 ms 798760 KB Output is correct
12 Correct 528 ms 804144 KB Output is correct
13 Correct 433 ms 797264 KB Output is correct
14 Correct 489 ms 811432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 102 ms 163436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 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 4796 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 6 ms 13148 KB Output is correct
11 Correct 6 ms 13148 KB Output is correct
12 Correct 7 ms 13272 KB Output is correct
13 Incorrect 518 ms 811504 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 1 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 4796 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Incorrect 674 ms 797924 KB Output isn't correct
11 Halted 0 ms 0 KB -