# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
850495 | 2023-09-16T17:44:57 Z | Benmath | Chase (CEOI17_chase) | C++14 | 142 ms | 96080 KB |
/****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <bits/stdc++.h> using namespace std; int n; int v; long long int p[100010]; vector<int> adjl[100010]; int vis[100010]; long long int dpnula[100010][105]; long long int dp[100010][105]; void dfs(int s){ vis[s]++; long long int suma = 0; for (int i = 0;i< adjl[s].size(); i++){ if(vis[adjl[s][i]] == 0){ suma = suma + p[adjl[s][i]]; } } for (int i = 0;i < adjl[s].size(); i++){ if (vis[adjl[s][i]] == 0){ dfs(adjl[s][i]); for (int j = 1; j <=v; j++){ dpnula[s][j] = max(dpnula[s][j], dpnula[adjl[s][i]][j-1] + suma); dpnula[s][j] = max(dpnula[s][j], dp[adjl[s][i]][j]); dp[s][j] = max(dp[s][j], dpnula[adjl[s][i]][j-1] + suma); dp[s][j] = max(dp[s][j], dp[adjl[s][i]][j]); } } } } int main(){ cin >> n; cin >> v; for(int i = 0; i < n; i++){ cin >> p[i]; } for(int i = 0; i < (n-1); i++){ int a, b; cin >> a >> b; adjl[a].push_back(b); adjl[b].push_back(a); } dfs(1); cout << dp[1][v]; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 3160 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 3160 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 142 ms | 96080 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 3160 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |