Submission #1093162

# Submission time Handle Problem Language Result Execution time Memory
1093162 2024-09-26T05:27:01 Z Luvidi Nestabilnost (COI23_nestabilnost) C++17
41 / 100
174 ms 197208 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fs first
#define sc second
#define pb push_back

const int maxn=5e3;
vector<int> adj[maxn];
int n;
ll dp[maxn+1][maxn+1],mn[maxn+1],a[maxn+1],f[maxn+1];

void dfs(int v,int p){
    for(int i:adj[v])if(i!=p)dfs(i,v);
    mn[v]=1e18;
    for(int i=1;i<=n;i++){
        if(a[v]>=i){
            dp[v][i]=1e18;
            continue;
        }
        dp[v][i]=f[i];
        for(int x:adj[v])if(x!=p){
            if(a[x]<i&&a[x]==(a[v]+1)%i){
                dp[v][i]+=min(mn[x],dp[x][i]-f[i]);
            }else{
                dp[v][i]+=mn[x];
            }
        }
        mn[v]=min(mn[v],dp[v][i]);
    }
}

void solve(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>f[i];
    for(int i=0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1,1);
    cout<<mn[1];
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 146 ms 197208 KB Output is correct
2 Correct 153 ms 197176 KB Output is correct
3 Correct 150 ms 197208 KB Output is correct
4 Correct 149 ms 197208 KB Output is correct
5 Correct 174 ms 197180 KB Output is correct
6 Correct 152 ms 197028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 52 ms 9868 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 612 KB Output is correct
2 Correct 1 ms 612 KB Output is correct
3 Correct 0 ms 616 KB Output is correct
4 Correct 0 ms 612 KB Output is correct
5 Correct 0 ms 612 KB Output is correct
6 Correct 0 ms 612 KB Output is correct
7 Correct 0 ms 612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 146 ms 197208 KB Output is correct
2 Correct 153 ms 197176 KB Output is correct
3 Correct 150 ms 197208 KB Output is correct
4 Correct 149 ms 197208 KB Output is correct
5 Correct 174 ms 197180 KB Output is correct
6 Correct 152 ms 197028 KB Output is correct
7 Correct 0 ms 612 KB Output is correct
8 Correct 1 ms 612 KB Output is correct
9 Correct 0 ms 616 KB Output is correct
10 Correct 0 ms 612 KB Output is correct
11 Correct 0 ms 612 KB Output is correct
12 Correct 0 ms 612 KB Output is correct
13 Correct 0 ms 612 KB Output is correct
14 Correct 157 ms 196500 KB Output is correct
15 Correct 160 ms 196468 KB Output is correct
16 Correct 158 ms 196516 KB Output is correct
17 Correct 169 ms 196436 KB Output is correct
18 Correct 160 ms 196692 KB Output is correct
19 Correct 159 ms 196692 KB Output is correct
20 Correct 151 ms 192596 KB Output is correct
21 Correct 154 ms 196432 KB Output is correct
22 Correct 153 ms 196352 KB Output is correct
23 Correct 154 ms 196432 KB Output is correct
24 Correct 154 ms 196688 KB Output is correct
25 Correct 147 ms 192596 KB Output is correct
26 Correct 146 ms 196436 KB Output is correct
27 Correct 156 ms 196564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 146 ms 197208 KB Output is correct
2 Correct 153 ms 197176 KB Output is correct
3 Correct 150 ms 197208 KB Output is correct
4 Correct 149 ms 197208 KB Output is correct
5 Correct 174 ms 197180 KB Output is correct
6 Correct 152 ms 197028 KB Output is correct
7 Runtime error 52 ms 9868 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -