Submission #579648

# Submission time Handle Problem Language Result Execution time Memory
579648 2022-06-19T14:59:34 Z AGE Džumbus (COCI19_dzumbus) C++14
0 / 110
882 ms 60264 KB
#include<bits/stdc++.h>
#define F first
#define S second
#define int long long
#define pb push_back
using namespace std;
const int N=1e6,M=2e3,mod=1e9+7;
int dp[M][M][2][2],a[N];
vector<int>adj[N];

void dfs(int node,int par){

    for(auto x:adj[node]){

        if(x==par)
            continue;

        for(int j=0;j<=1000;j++){
            /*dp[node][j][0][0];
            dp[node][j][0][1];
            dp[node][j][1][1];
            dp[node][j][1][0];*/

            dp[x][j][0][0]=min(dp[x][j][0][0],dp[node][j][0][0]);
            dp[x][j][1][0]=min(dp[x][j][1][0],dp[node][j][0][0]+a[x]);
            dp[x][j][1][0]=min(dp[x][j][1][0],dp[node][j][0][1]+a[x]);
            dp[x][j][0][0]=min(dp[x][j][0][0],dp[node][j][0][1]);
            dp[x][j][0][1]=min(dp[x][j][0][1],dp[node][j][1][1]);

            if(j>0)
                dp[x][j][1][1]=min(dp[x][j][1][1],dp[node][j-1][1][1]+a[x]);

            dp[x][j][0][1]=min(dp[x][j][0][1],dp[node][j][1][0]);

            if(j>1)
                dp[x][j][1][1]=min(dp[x][j][1][1],dp[node][j-2][1][0]+a[x]);

        }

        dfs(x,node);

    }

}
main(){


    int n,m;
    cin>>n>>m;

    for(int i=1;i<=n;i++)
        cin>>a[i];

    for(int i=0;i<m;i++){

        int x,y;
        cin>>x>>y;

        adj[x].pb(y);
        adj[y].pb(x);

    }

    int node=1,par=0;

    for(int i=0;i<=1000;i++)
        for(int j=0;j<=1000;j++)
            for(int k=0;k<2;k++)
                for(int kk=0;kk<2;kk++)
                    dp[i][j][k][kk]=1e18;

    for(int i=1;i<=n;i++)
        if(adj[i].size()==1)
            node=i;

    dp[node][0][0][0]=0;
    dp[node][0][1][0]=a[node];

    dfs(node,0);

    int node2;
    for(int i=1;i<=n;i++)
        if(adj[i].size()==1&&node!=i)
            node2=i;

    int q;
    cin>>q;

    while(q--){

        int val;
        cin>>val;

        int ans=-1e18;

        for(int i=0;i<=1000;i++){
            for(int j=0;j<2;j++)
                for(int k=0;k<2;k++)
                    if(dp[node2][i][j][k]<=val)
                        ans=max(ans,i);
        }

        cout<<ans<<"!"<<endl;

    }


    return 0;
}

Compilation message

dzumbus.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   45 | main(){
      | ^~~~
dzumbus.cpp: In function 'int main()':
dzumbus.cpp:64:16: warning: unused variable 'par' [-Wunused-variable]
   64 |     int node=1,par=0;
      |                ^~~
dzumbus.cpp:81:9: warning: 'node2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   81 |     int node2;
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 59476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 59476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 882 ms 60264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 59476 KB Output isn't correct
2 Halted 0 ms 0 KB -