Submission #77243

# Submission time Handle Problem Language Result Execution time Memory
77243 2018-09-24T09:35:56 Z farukkastamonuda Dynamite (POI11_dyn) C++14
0 / 100
1786 ms 27096 KB
#include <bits/stdc++.h>
#define li 300005
#define mid (bas+son)/2
using namespace std;
int n,m,ans,A[li],x,y,say;
vector<int> vv[li];
int solve(int node,int ata,int sayi){
    int t=0,v=0;
    for(int i=0;i<(int)vv[node].size();i++){
        int go=vv[node][i];
        if(ata==go) continue;
        int u=solve(go,node,sayi);
        if(u==0) continue;
        if(u>0) v=max(v,u);
        else t=min(t,u);
    }
    if(abs(t)>=sayi){
        ans++;
        return sayi;
    }
    if(t==0 && v==0) return A[node];
    if(v>abs(t)) return v-1;
    return t-1;
}
int can(int k){
    ans=0;
    if(solve(1,0,k)<0) ans++;
    if(ans<=k) return 1;
    return 0;
}
int main(){
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++) {scanf("%d",&A[i]);say+=A[i];}
    for(int i=1;i<n;i++){
        scanf("%d %d",&x,&y);
        vv[x].push_back(y);
        vv[y].push_back(x);
    }
    if(say<=m){
        printf("0\n");
        return 0;
    }
    int bas=1,son=n-1;
    while(bas<=son){
        if(can(mid)==1) son=mid-1;
        else bas=mid+1;
    }
    printf("%d\n",bas);
    return 0;
}

Compilation message

dyn.cpp: In function 'int main()':
dyn.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~
dyn.cpp:33:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++) {scanf("%d",&A[i]);say+=A[i];}
                            ~~~~~^~~~~~~~~~~~
dyn.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&x,&y);
         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 8 ms 7548 KB Output is correct
3 Correct 8 ms 7548 KB Output is correct
4 Incorrect 8 ms 7548 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 7556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 7556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 7556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 7952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 57 ms 9632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 136 ms 11336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 767 ms 15048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1786 ms 20916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1746 ms 27096 KB Output isn't correct
2 Halted 0 ms 0 KB -