# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
101588 | 2019-03-19T04:43:06 Z | jamielim | Chase (CEOI17_chase) | C++14 | 2238 ms | 93556 KB |
#include <bits/stdc++.h> using namespace std; int n,v; vector<int> adj[100005]; long long arr[100005]; long long pigeons[100005]; long long memo[100005][105]; long long dp(int x,int vleft,int p){ if(memo[x][vleft]!=-1)return memo[x][vleft]; if(vleft==0)return memo[x][0]=0; if(adj[x].size()==0)return memo[x][vleft]=pigeons[x]-(p==-1?0:arr[p]); long long ans=0; for(int i=0;i<(int)adj[x].size();i++){ if(adj[x][i]==p)continue; ans=max(ans,max(dp(adj[x][i],vleft,x),dp(adj[x][i],vleft-1,x)+pigeons[x]-(p==-1?0:arr[p]))); } return memo[x][vleft]=ans; } int main(){ scanf("%d%d",&n,&v); for(int i=0;i<n;i++){ scanf("%d",&arr[i]); } int a,b; for(int i=0;i<n-1;i++){ scanf("%d%d",&a,&b); a--; b--; adj[a].push_back(b); adj[b].push_back(a); } for(int i=0;i<n;i++){ pigeons[i]=0; for(int j=0;j<(int)adj[i].size();j++){ pigeons[i]+=arr[adj[i][j]]; } } if(n<=1000){ long long ans=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ for(int k=0;k<=v;k++){ memo[j][k]=-1; } } ans=max(ans,dp(i,v,-1)); } printf("%lld",ans); return 0; } memset(memo,-1,sizeof(memo)); printf("%lld",dp(0,v,-1)); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2688 KB | Output is correct |
2 | Correct | 5 ms | 2688 KB | Output is correct |
3 | Correct | 0 ms | 2688 KB | Output is correct |
4 | Correct | 4 ms | 2688 KB | Output is correct |
5 | Correct | 6 ms | 2688 KB | Output is correct |
6 | Correct | 5 ms | 2688 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2688 KB | Output is correct |
2 | Correct | 5 ms | 2688 KB | Output is correct |
3 | Correct | 0 ms | 2688 KB | Output is correct |
4 | Correct | 4 ms | 2688 KB | Output is correct |
5 | Correct | 6 ms | 2688 KB | Output is correct |
6 | Correct | 5 ms | 2688 KB | Output is correct |
7 | Correct | 1841 ms | 3632 KB | Output is correct |
8 | Correct | 143 ms | 3584 KB | Output is correct |
9 | Correct | 55 ms | 3584 KB | Output is correct |
10 | Correct | 330 ms | 3584 KB | Output is correct |
11 | Correct | 246 ms | 3584 KB | Output is correct |
12 | Correct | 215 ms | 3704 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2132 ms | 93556 KB | Output is correct |
2 | Correct | 2238 ms | 93512 KB | Output is correct |
3 | Correct | 161 ms | 89964 KB | Output is correct |
4 | Correct | 234 ms | 89684 KB | Output is correct |
5 | Correct | 978 ms | 89796 KB | Output is correct |
6 | Correct | 769 ms | 89704 KB | Output is correct |
7 | Correct | 819 ms | 89724 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2688 KB | Output is correct |
2 | Correct | 5 ms | 2688 KB | Output is correct |
3 | Correct | 0 ms | 2688 KB | Output is correct |
4 | Correct | 4 ms | 2688 KB | Output is correct |
5 | Correct | 6 ms | 2688 KB | Output is correct |
6 | Correct | 5 ms | 2688 KB | Output is correct |
7 | Correct | 1841 ms | 3632 KB | Output is correct |
8 | Correct | 143 ms | 3584 KB | Output is correct |
9 | Correct | 55 ms | 3584 KB | Output is correct |
10 | Correct | 330 ms | 3584 KB | Output is correct |
11 | Correct | 246 ms | 3584 KB | Output is correct |
12 | Correct | 215 ms | 3704 KB | Output is correct |
13 | Correct | 2132 ms | 93556 KB | Output is correct |
14 | Correct | 2238 ms | 93512 KB | Output is correct |
15 | Correct | 161 ms | 89964 KB | Output is correct |
16 | Correct | 234 ms | 89684 KB | Output is correct |
17 | Correct | 978 ms | 89796 KB | Output is correct |
18 | Correct | 769 ms | 89704 KB | Output is correct |
19 | Correct | 819 ms | 89724 KB | Output is correct |
20 | Incorrect | 292 ms | 91788 KB | Output isn't correct |
21 | Halted | 0 ms | 0 KB | - |