| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 722693 | rainboy | Winter Driving (CCO19_day1problem3) | C11 | 1044 ms | 14276 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include <stdlib.h>
#define N 200000
long long max(long long a, long long b) { return a > b ? a : b; }
int *ej[N], eo[N];
void append(int i, int j) {
int o = eo[i]++;
if (o >= 2 && (o & o - 1) == 0)
ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
ej[i][o] = j;
}
int aa[N]; long long dp[N], dq[N];
void dfs(int p, int i) {
int o;
dp[i] = aa[i], dq[i] = 0;
for (o = eo[i]; o--; ) {
int j = ej[i][o];
if (j != p) {
dfs(i, j);
dp[i] += dp[j], dq[i] += dq[j];
}
}
dq[i] += aa[i] * dp[i];
}
int main() {
int n, i, j, o, b;
long long ans, sum1, sum2;
scanf("%d", &n);
for (i = 0; i < n; i++)
ej[i] = (int *) malloc(2 * sizeof *ej[i]);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
for (j = 1; j < n; j++) {
scanf("%d", &i), i--;
append(i, j), append(j, i);
}
ans = 0;
for (i = 0; i < n; i++) {
dfs(-1, i);
for (b = 0; b < 1 << eo[i]; b++) {
sum1 = sum2 = 0;
for (o = 0; o < eo[i]; o++) {
j = ej[i][o];
if ((b & 1 << o) == 0)
sum1 += dp[j];
else
sum2 += dp[j];
}
ans = max(ans, dq[i] + (long long) sum1 * sum2);
}
}
for (i = 0; i < n; i++)
ans -= aa[i];
printf("%lld\n", ans);
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... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
