Submission #880854

# Submission time Handle Problem Language Result Execution time Memory
880854 2023-11-30T07:14:12 Z lampooppp Džumbus (COCI19_dzumbus) C++17
0 / 110
163 ms 34132 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int inf = 1e16;
const int N=1e3+100;
vector<int> adj[N+1];
int d[N+1],n,m;
bool avail[N+1];
int dp[N+1][N+1][2], sz[N+1];

void dfs(int u, int par)
{
    avail[u]=1;
    for(int v : adj[u])
    {
        if(v!=par) dfs(v, u);
    }
}

void solve(int u, int par)
{
    cout << u << '\n';
    //dp[u][0][1]=d[u];
    //dp[u][0][0]=0;
    sz[u]=1;
    for(int v : adj[u])
    {
        if(v!=par)
        {
            solve(v,u);
            for(int j = sz[u]; j>=0;--j)
            {
                for(int k = sz[v]; k >=0;--k)
                {
                    dp[u][j+k][0] = min(dp[u][j+k][0], dp[u][j][0] + min(dp[v][k][1], dp[v][k][0]));
                    if(j>0) dp[u][j+k][1] = min(dp[u][j+k][1], dp[u][j-1][0] + dp[v][k][1] + d[u]);
                    if(k>0) dp[u][j+k][1] = min(dp[u][j+k][1], dp[u][j][1] + dp[v][k-1][0] + d[v]);
                    if(j>0 && k>0) dp[u][j+k][1] = min(dp[u][j+k][1], dp[u][j-1][0] + dp[v][k-1][0]+d[u]+d[v]);
                    dp[u][j+k][1] = min(dp[u][j+k][1], min(dp[u][j][1] + dp[v][k][0], dp[u][j][1] + dp[v][k][1]));
                    cout << j << " " << k << " " << dp[u][j+k][0] << " " << dp[u][j+k][1] << '\n';
                }
            }
            sz[u]+=sz[v];
        }
    }
    cout << u << '\n';
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
   // freopen("dcm.out", "w", stdout);
    int n,m;
    cin >> n >> m;
    for(int i=1;i<=n;++i) cin >> d[i];
    for(int i=1;i<=m;++i)
    {
        int u,v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=1;i<=n;++i)
    {
        if(!avail[i])
        {dfs(i, 0);
        adj[0].push_back(i);}
    }
   // cout << "K";
    for(int i=0;i<=n;++i)
    {
        for(int j=1;j<=n;++j)
        {
            dp[i][j][0]=dp[i][j][1]=inf;
        }
        dp[i][0][1]=inf;
    }
  //  cout << "K";
    solve(0,0);
    int q;
    cin >> q;
    //cout << "LLL";
    while(q--)
    {
        //cout << "lll";
        int D;
        cin>>D;
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            if(dp[0][i][0]<=D) ans=i;
        }
        cout<<ans<<"\n";
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 163 ms 34132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 163 ms 34132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 4084 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 163 ms 34132 KB Output isn't correct
2 Halted 0 ms 0 KB -