Submission #855537

#TimeUsernameProblemLanguageResultExecution timeMemory
855537mychecksedadMagic Tree (CEOI19_magictree)C++17
22 / 100
674 ms811504 KiB
/* 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 (stderr)

magictree.cpp: In function 'int main()':
magictree.cpp:61:15: warning: unused variable 'aa' [-Wunused-variable]
   61 |   int tt = 1, aa;
      |               ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...