# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
121583 |
2019-06-26T19:43:38 Z |
sofhiasouza |
Chase (CEOI17_chase) |
C++14 |
|
4000 ms |
98984 KB |
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long int ll;
const int maxn = 1e5+10;
int n, v, vet[maxn];
ll dp[maxn][110];
vector < int > grafo[maxn];
ll dfs(int u, int val, int pai)
{
if(val == 0) return 0;
if(dp[u][val]) return dp[u][val];
ll resp1 = 0, resp2 = 0, cont = 0;
for(int i = 0 ; i < grafo[u].size() ; i++)
{
int v = grafo[u][i];
if(v == pai) continue;
cont += vet[v];
resp1 = max(resp1, dfs(v, val-1, u));
resp2 = max(resp2, dfs(v, val, u));
}
resp1 += cont;
return dp[u][val] = max(resp1, resp2);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> v;
for(int i = 1 ; i <= n ; i++) cin >> vet[i];
for(int i = 0 ; i < n-1 ; i++)
{
int a, b;
cin >> a >> b;
grafo[a].pb(b);
grafo[b].pb(a);
}
ll resp = dfs(1, v, 0);
if(n <= 1000)
{
for(int i = 2 ; i <= n ; i++)
{
memset(dp, 0, sizeof dp);
resp = max(resp, dfs(i, v, 0));
}
}
cout << resp << endl;
}
Compilation message
chase.cpp: In function 'll dfs(int, int, int)':
chase.cpp:19:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0 ; i < grafo[u].size() ; i++)
~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
88968 KB |
Output is correct |
2 |
Correct |
222 ms |
88952 KB |
Output is correct |
3 |
Correct |
227 ms |
88952 KB |
Output is correct |
4 |
Correct |
221 ms |
88972 KB |
Output is correct |
5 |
Correct |
232 ms |
88884 KB |
Output is correct |
6 |
Correct |
200 ms |
88824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
88968 KB |
Output is correct |
2 |
Correct |
222 ms |
88952 KB |
Output is correct |
3 |
Correct |
227 ms |
88952 KB |
Output is correct |
4 |
Correct |
221 ms |
88972 KB |
Output is correct |
5 |
Correct |
232 ms |
88884 KB |
Output is correct |
6 |
Correct |
200 ms |
88824 KB |
Output is correct |
7 |
Execution timed out |
4018 ms |
88908 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1273 ms |
98984 KB |
Output is correct |
2 |
Correct |
1370 ms |
98936 KB |
Output is correct |
3 |
Correct |
137 ms |
94580 KB |
Output is correct |
4 |
Correct |
159 ms |
94200 KB |
Output is correct |
5 |
Correct |
548 ms |
94260 KB |
Output is correct |
6 |
Correct |
499 ms |
94328 KB |
Output is correct |
7 |
Correct |
576 ms |
94312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
88968 KB |
Output is correct |
2 |
Correct |
222 ms |
88952 KB |
Output is correct |
3 |
Correct |
227 ms |
88952 KB |
Output is correct |
4 |
Correct |
221 ms |
88972 KB |
Output is correct |
5 |
Correct |
232 ms |
88884 KB |
Output is correct |
6 |
Correct |
200 ms |
88824 KB |
Output is correct |
7 |
Execution timed out |
4018 ms |
88908 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |