답안 #77245

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
77245 2018-09-24T09:39:11 Z farukkastamonuda Dynamite (POI11_dyn) C++14
90 / 100
1970 ms 66500 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<=m) 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);
         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7288 KB Output is correct
2 Correct 8 ms 7544 KB Output is correct
3 Correct 8 ms 7596 KB Output is correct
4 Correct 8 ms 7596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7596 KB Output is correct
2 Correct 8 ms 7596 KB Output is correct
3 Correct 8 ms 7596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7652 KB Output is correct
2 Correct 8 ms 7692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7700 KB Output is correct
2 Correct 8 ms 7736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 8276 KB Output is correct
2 Correct 45 ms 8988 KB Output is correct
3 Correct 43 ms 9608 KB Output is correct
4 Correct 56 ms 11680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 11680 KB Output is correct
2 Correct 106 ms 12740 KB Output is correct
3 Correct 168 ms 13908 KB Output is correct
4 Correct 144 ms 17824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 17824 KB Output is correct
2 Correct 156 ms 17824 KB Output is correct
3 Correct 309 ms 18336 KB Output is correct
4 Correct 306 ms 25028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 691 ms 25028 KB Output is correct
2 Correct 758 ms 28612 KB Output is correct
3 Correct 1426 ms 39812 KB Output is correct
4 Correct 1408 ms 43364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1970 ms 43364 KB Output is correct
2 Correct 1334 ms 43364 KB Output is correct
3 Correct 1882 ms 52176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1636 ms 55876 KB Output is correct
2 Correct 1291 ms 55876 KB Output is correct
3 Runtime error 1913 ms 66500 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
4 Halted 0 ms 0 KB -