# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
122558 | sofhiasouza | Chase (CEOI17_chase) | C++14 | 279 ms | 82168 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long int ll;
const int maxn = 1e5+10;
vector < int > grafo[maxn];
int n, v, vet[maxn];
ll soma[maxn], dp[maxn][110];
void dfs(int u, int pai)
{
for(int i = 0 ; i < grafo[u].size() ; i++)
{
int k = grafo[u][i];
if(k == pai) continue;
dfs(k, u);
for(int j = 1 ; j <= v ; j++)
{
dp[u][j] = max({dp[u][j], dp[k][j-1] + soma[k] - vet[u], dp[k][j]});
}
}
}
int main()
{
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(int j = 0 ; j < grafo[i].size() ; j++)
{
soma[i] += vet[grafo[i][j]];
}
}
grafo[0].pb(1);
dfs(0, 0);
cout << dp[0][v] << endl;
}
컴파일 시 표준 에러 (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... |