# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
850500 | 2023-09-16T17:52:18 Z | Benmath | Chase (CEOI17_chase) | C++14 | 191 ms | 149584 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 = 1; 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 | Correct | 142 ms | 94036 KB | Output is correct |
2 | Correct | 147 ms | 96336 KB | Output is correct |
3 | Correct | 94 ms | 9924 KB | Output is correct |
4 | Correct | 150 ms | 145488 KB | Output is correct |
5 | Correct | 187 ms | 149584 KB | Output is correct |
6 | Correct | 191 ms | 149584 KB | Output is correct |
7 | Correct | 185 ms | 149328 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 3160 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |