# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
121689 | 2019-06-27T00:24:14 Z | sofhiasouza | Chase (CEOI17_chase) | C++14 | 727 ms | 79124 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], soma[maxn]; 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 < (int) grafo[u].size() ; i++) { int v = grafo[u][i]; if(v == pai) continue; dp[u][val] = max({dp[u][val], dfs(v, val, u), dfs(v, val-1, u) + soma[v] - vet[u]}); } return dp[u][val]; } void roda(int u, int pai) { } 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); } for(int i = 1; i <= n; i++) { for(auto v : grafo[i]) { soma[i] += vet[v]; } } ll resp = max(dfs(1, v, 0), dfs(1, v-1, 0) + soma[1]); if(n <= 1000) { for(int i = 2 ; i <= n ; i++) { for(int j = 0 ; j <= n ; j++) for(int k = 0 ; k <= v ; k++) dp[j][k] = 0; resp = max(dfs(i, v, 0), dfs(i, v-1, 0) + soma[i]); } } cout << resp << endl; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 2688 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 2688 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 314 ms | 55096 KB | Output is correct |
2 | Correct | 315 ms | 55032 KB | Output is correct |
3 | Correct | 65 ms | 7684 KB | Output is correct |
4 | Correct | 146 ms | 78044 KB | Output is correct |
5 | Correct | 705 ms | 79124 KB | Output is correct |
6 | Correct | 727 ms | 79000 KB | Output is correct |
7 | Correct | 664 ms | 78716 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 2688 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |