# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
61780 | IvanC | Chase (CEOI17_chase) | C++17 | 369 ms | 104840 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;
const int MAXC = 1e2 + 5;
vector<int> grafo[MAXN];
ll dp[MAXN][MAXC],P[MAXN],somatorio[MAXN],best;
int N,C;
void dfs(int v,int p){
somatorio[v] = 0;
for(int i = 0;i<=C;i++) dp[v][i] = 0;
for(int u : grafo[v]){
if(u == p) continue;
dfs(u,v);
somatorio[v] += P[u];
}
for(int u : grafo[v]){
if(u == p) continue;
for(int i = 1;i<=C;i++){
dp[v][i] = max(dp[v][i], max(dp[u][i], dp[u][i-1] + somatorio[v] ) );
}
}
}
int main(){
scanf("%d %d",&N,&C);
for(int i = 1;i<=N;i++){
scanf("%lld",&P[i]);
}
for(int i = 1;i<N;i++){
int u,v;
scanf("%d %d",&u,&v);
grafo[u].push_back(v);
grafo[v].push_back(u);
}
int limite = N;
if(N > 1000) limite = 1;
for(int i = 1;i<=limite;i++){
dfs(i,-1);
for(int j = 0;j<=C;j++) best = max(best,dp[i][j]);
}
printf("%lld\n",best);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |