# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
791630 | 2023-07-24T08:22:15 Z | 박상훈(#10047) | Nestabilnost (COI23_nestabilnost) | C++17 | 175 ms | 199032 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n; vector<int> adj[5050]; ll dp[5050][5050], ans[5050]; int a[5050], f[5050]; void dfs_naive(int s, int pa = 0){ for (int i=a[s]+1;i<=n;i++) dp[s][i] = f[i]; for (auto &v:adj[s]) if (v!=pa){ dfs_naive(v, s); for (int i=a[s]+1;i<=n;i++){ if (i <= a[v]) dp[s][i] += ans[v]; else if (a[v]==0 && a[s]+1==i) dp[s][i] += min(ans[v], dp[v][i] - f[i]); else if (a[v]>0 && a[s]+1==a[v]) dp[s][i] += min(ans[v], dp[v][i] - f[i]); else dp[s][i] += ans[v]; } } ans[s] = *min_element(dp[s]+a[s]+1, dp[s]+n+1); } int main(){ scanf("%d", &n); for (int i=1;i<=n;i++) scanf("%d", a+i); for (int i=1;i<=n;i++) scanf("%d", f+i); for (int i=1;i<=n-1;i++){ int x, y; scanf("%d %d", &x, &y); adj[x].push_back(y); adj[y].push_back(x); } dfs_naive(1); printf("%lld\n", ans[1]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 143 ms | 198908 KB | Output is correct |
2 | Correct | 147 ms | 198952 KB | Output is correct |
3 | Correct | 131 ms | 187380 KB | Output is correct |
4 | Correct | 149 ms | 199032 KB | Output is correct |
5 | Correct | 142 ms | 198852 KB | Output is correct |
6 | Correct | 175 ms | 198928 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 56 ms | 7044 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 468 KB | Output is correct |
2 | Correct | 0 ms | 468 KB | Output is correct |
3 | Correct | 0 ms | 468 KB | Output is correct |
4 | Correct | 1 ms | 468 KB | Output is correct |
5 | Correct | 1 ms | 468 KB | Output is correct |
6 | Correct | 1 ms | 468 KB | Output is correct |
7 | Correct | 1 ms | 468 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 143 ms | 198908 KB | Output is correct |
2 | Correct | 147 ms | 198952 KB | Output is correct |
3 | Correct | 131 ms | 187380 KB | Output is correct |
4 | Correct | 149 ms | 199032 KB | Output is correct |
5 | Correct | 142 ms | 198852 KB | Output is correct |
6 | Correct | 175 ms | 198928 KB | Output is correct |
7 | Correct | 0 ms | 468 KB | Output is correct |
8 | Correct | 0 ms | 468 KB | Output is correct |
9 | Correct | 0 ms | 468 KB | Output is correct |
10 | Correct | 1 ms | 468 KB | Output is correct |
11 | Correct | 1 ms | 468 KB | Output is correct |
12 | Correct | 1 ms | 468 KB | Output is correct |
13 | Correct | 1 ms | 468 KB | Output is correct |
14 | Correct | 164 ms | 198396 KB | Output is correct |
15 | Correct | 153 ms | 198400 KB | Output is correct |
16 | Correct | 146 ms | 198376 KB | Output is correct |
17 | Correct | 153 ms | 198412 KB | Output is correct |
18 | Correct | 147 ms | 198336 KB | Output is correct |
19 | Correct | 144 ms | 198460 KB | Output is correct |
20 | Correct | 124 ms | 194448 KB | Output is correct |
21 | Correct | 136 ms | 198284 KB | Output is correct |
22 | Correct | 142 ms | 198184 KB | Output is correct |
23 | Correct | 128 ms | 198264 KB | Output is correct |
24 | Correct | 130 ms | 198288 KB | Output is correct |
25 | Correct | 126 ms | 194012 KB | Output is correct |
26 | Correct | 131 ms | 197832 KB | Output is correct |
27 | Correct | 131 ms | 197276 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 143 ms | 198908 KB | Output is correct |
2 | Correct | 147 ms | 198952 KB | Output is correct |
3 | Correct | 131 ms | 187380 KB | Output is correct |
4 | Correct | 149 ms | 199032 KB | Output is correct |
5 | Correct | 142 ms | 198852 KB | Output is correct |
6 | Correct | 175 ms | 198928 KB | Output is correct |
7 | Runtime error | 56 ms | 7044 KB | Execution killed with signal 11 |
8 | Halted | 0 ms | 0 KB | - |