답안 #579671

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
579671 2022-06-19T15:34:11 Z AGE Džumbus (COCI19_dzumbus) C++14
0 / 110
366 ms 59984 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];

int node2;
bool ok(int mid,int val){

    for(int j=0;j<2;j++){
        for(int k=0;k<2;k++){
            if(dp[node2][mid][j][k]<=val)
                return 1;
        }
    }

    return 0;
}
void dfs(int node,int par){

    for(auto x:adj[node]){

        if(x==par)
            continue;

        for(int j=0;j<=1000;j++){

            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);

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

    int q;
    cin>>q;

    /*for(int i=1000;i>=0;i--)
        for(int j=0;j<2;j++)
            for(int k=0;k<2;k++)
                dp[node2][i][j][k]=min(dp[node2][i][j][k],dp[node2][i+1][j][k]);
*/

    while(q--){

        int val;
        cin>>val;

        int ans=-1e18;
        int l=0,r=1000;
        while(l<r){

            int okk=0;
            int mid=(l+r+1)/2;

            if(ok(mid,val))
                l=mid;

            else r=mid-1;

        }

        cout<<l<<endl;

    }


    return 0;
}

Compilation message

dzumbus.cpp:53:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   53 | main(){
      | ^~~~
dzumbus.cpp: In function 'int main()':
dzumbus.cpp:111:17: warning: unused variable 'okk' [-Wunused-variable]
  111 |             int okk=0;
      |                 ^~~
dzumbus.cpp:107:13: warning: unused variable 'ans' [-Wunused-variable]
  107 |         int ans=-1e18;
      |             ^~~
dzumbus.cpp:72:16: warning: unused variable 'par' [-Wunused-variable]
   72 |     int node=1,par=0;
      |                ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 59432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 59432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 366 ms 59984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 59432 KB Output isn't correct
2 Halted 0 ms 0 KB -