# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
101601 | 2019-03-19T05:01:23 Z | dantoh000 | Chase (CEOI17_chase) | C++14 | 2181 ms | 94884 KB |
#include <bits/stdc++.h> #define int long long using namespace std; const int maxn = 100005; int p[maxn]; int childsum[maxn]; vector<int> adjlist[maxn]; int memo[maxn][105]; int pa[maxn]; int dp(int id, int x){ //printf("at %d with %d\n",id,x); if (x == 0) return 0; if (memo[id][x] != -1) return memo[id][x]; memo[id][x] = 0; //printf("if drop at %d, will encounter %d more pigeons\n",id,childsum[id]); for (auto v : adjlist[id]){ if (pa[id] == v) continue; pa[v] = id; memo[id][x] = max(memo[id][x],max(dp(v,x),dp(v,x-1)+childsum[id]-p[pa[id]])); } return memo[id][x]; } main(){ memset(memo,-1,sizeof(memo)); int n,v; scanf("%lld%lld",&n,&v); for (int i = 1; i <= n; i++) scanf("%lld",&p[i]); for (int i = 0; i < n-1; i++){ int a,b; scanf("%lld%lld",&a,&b); adjlist[a].push_back(b); adjlist[b].push_back(a); childsum[a] += p[b]; childsum[b] += p[a]; } int ans = 0; if (n <= 100){ for (int i = 1; i <= n; i++){ //printf("\n\nstarting at %d\n",i); memset(memo,-1,sizeof(memo)); memset(pa,-1,sizeof(pa)); pa[i] = 0; //printf("%d\n",dp(i,v)); ans = max(ans,dp(i,v)); } } else{ ans = dp(1,v); } printf("%lld",ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 261 ms | 85884 KB | Output is correct |
2 | Correct | 262 ms | 85696 KB | Output is correct |
3 | Correct | 255 ms | 85624 KB | Output is correct |
4 | Correct | 264 ms | 85720 KB | Output is correct |
5 | Correct | 269 ms | 85964 KB | Output is correct |
6 | Correct | 243 ms | 85752 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 261 ms | 85884 KB | Output is correct |
2 | Correct | 262 ms | 85696 KB | Output is correct |
3 | Correct | 255 ms | 85624 KB | Output is correct |
4 | Correct | 264 ms | 85720 KB | Output is correct |
5 | Correct | 269 ms | 85964 KB | Output is correct |
6 | Correct | 243 ms | 85752 KB | Output is correct |
7 | Incorrect | 81 ms | 84928 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2181 ms | 94860 KB | Output is correct |
2 | Correct | 2150 ms | 94884 KB | Output is correct |
3 | Correct | 136 ms | 91112 KB | Output is correct |
4 | Correct | 175 ms | 90928 KB | Output is correct |
5 | Correct | 809 ms | 91000 KB | Output is correct |
6 | Correct | 708 ms | 90992 KB | Output is correct |
7 | Correct | 840 ms | 91116 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 261 ms | 85884 KB | Output is correct |
2 | Correct | 262 ms | 85696 KB | Output is correct |
3 | Correct | 255 ms | 85624 KB | Output is correct |
4 | Correct | 264 ms | 85720 KB | Output is correct |
5 | Correct | 269 ms | 85964 KB | Output is correct |
6 | Correct | 243 ms | 85752 KB | Output is correct |
7 | Incorrect | 81 ms | 84928 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |