# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
791828 |
2023-07-24T10:39:38 Z |
이동현(#10049) |
Nestabilnost (COI23_nestabilnost) |
C++17 |
|
1500 ms |
45068 KB |
#include <bits/stdc++.h>
#define int long long
#define mi(x, y) (x = min(x, y))
#define ma(x, y) (x = max(x, y))
using namespace std;
const int NS = (int)3e5 + 4;
int n;
int a[NS], f[NS], mn[NS];
int dp[NS];
vector<int> len[NS];
vector<int> way[NS];
int md;
void sol3(int rt, int x, int pr){
for(auto&nxt:way[x]){
if(nxt == pr){
continue;
}
if(a[x] + 1 == a[nxt]){
sol3(rt, nxt, x);
}
else{
len[rt].push_back(a[x]);
}
}
}
int sol2(int x, int pr){
int rv = 0;
for(auto&nxt:way[x]){
if(nxt == pr){
continue;
}
if((a[x] + 1) % md == a[nxt]){
rv += sol2(nxt, x);
}
else{
rv += dp[nxt];
}
}
if(dp[x]){
rv = min(rv, dp[x]);
}
return rv;
}
void sol(int x, int pr){
for(auto&nxt:way[x]){
if(nxt == pr){
continue;
}
sol(nxt, x);
}
md = (int)1e18;
dp[x] = sol2(x, pr) + mn[a[x]];
sol3(x, x, pr);
for(int i = a[x]; i < n; ++i){
md = i + 1;
dp[x] = min(dp[x], sol2(x, pr) + f[i]);
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 0; i < n; ++i){
cin >> a[i];
}
for(int i = 0; i < n; ++i){
cin >> f[i];
}
for(int i = n - 1; i >= 0; --i){
mn[i] = f[i];
if(i + 1 < n){
mn[i] = min(mn[i], mn[i + 1]);
}
}
for(int i = 1; i < n; ++i){
int x, y;
cin >> x >> y;
--x, --y;
way[x].push_back(y);
way[y].push_back(x);
}
sol(0, -1);
cout << dp[0] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
462 ms |
15184 KB |
Output is correct |
2 |
Correct |
344 ms |
15208 KB |
Output is correct |
3 |
Execution timed out |
1587 ms |
15096 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1570 ms |
45068 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14424 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Incorrect |
6 ms |
14420 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
462 ms |
15184 KB |
Output is correct |
2 |
Correct |
344 ms |
15208 KB |
Output is correct |
3 |
Execution timed out |
1587 ms |
15096 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
462 ms |
15184 KB |
Output is correct |
2 |
Correct |
344 ms |
15208 KB |
Output is correct |
3 |
Execution timed out |
1587 ms |
15096 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |