답안 #44210

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
44210 2018-03-30T14:16:02 Z imaxblue Dynamite (POI11_dyn) C++17
60 / 100
1829 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() ((rand() << 14)+rand())
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;
#define pi 3.14159265358979323846

int n, k, a, b, lo, mid, hi=300000, c;
int block[300005], need[300005];
bool u[300005];
vector<int> v[300005];
void dfs(int N, int P){
    block[N]=1;
    need[N]=0;
    fox(l, v[N].size()){
        if (v[N][l]==P) continue;
        dfs(v[N][l], N);
        block[N]=min(block[N], block[v[N][l]]+1);
        need[N]=max(need[N], need[v[N][l]]+1);
    }
    if (-block[N]>=need[N]){
        need[N]=-1;
        return;
    }
    if (need[N]==mid || P==-1){
        c++;
        //if (mid==0) cout << N << ' ';
        need[N]=-1;
        block[N]=-mid;
        return;
    }
    block[N]=0;
}
int solve(){
    while(lo<hi){
        mid=(lo+hi)/2;
        c=0;
        dfs(1, -1);
        if (c<=k) hi=mid;
        else lo=mid+1;
    }
    c=0; mid=0;
    //cout << endl;
    dfs(1, -1);
    //cout << c << endl;
    return lo;
}
int main(){
    scan(n); scan(k);
    fox1(l, n) scanf("%i", &u[l]);
    fox(l, n-1){
        scan(a); scan(b);
        v[a].pb(b);
        v[b].pb(a);
    }
    cout << solve();
    return 0;
}

Compilation message

dyn.cpp: In function 'void dfs(int, int)':
dyn.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define fox(k, x) for (int k=0; k<x; ++k)
dyn.cpp:37:9:
     fox(l, v[N].size()){
         ~~~~~~~~~~~~~~            
dyn.cpp:37:5: note: in expansion of macro 'fox'
     fox(l, v[N].size()){
     ^~~
dyn.cpp: In function 'int main()':
dyn.cpp:72:33: warning: format '%i' expects argument of type 'int*', but argument 2 has type 'bool*' [-Wformat=]
     fox1(l, n) scanf("%i", &u[l]);
                            ~~~~~^
dyn.cpp:72:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fox1(l, n) scanf("%i", &u[l]);
                ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7288 KB Output is correct
2 Correct 7 ms 7400 KB Output is correct
3 Correct 7 ms 7512 KB Output is correct
4 Correct 7 ms 7644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 7644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 7748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 7748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 8276 KB Output is correct
2 Incorrect 43 ms 9052 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 11156 KB Output is correct
2 Correct 117 ms 12972 KB Output is correct
3 Correct 216 ms 14244 KB Output is correct
4 Correct 177 ms 17624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 200 ms 17624 KB Output is correct
2 Correct 214 ms 19152 KB Output is correct
3 Correct 365 ms 20292 KB Output is correct
4 Correct 300 ms 25768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 778 ms 28812 KB Output is correct
2 Correct 978 ms 33980 KB Output is correct
3 Correct 1517 ms 43560 KB Output is correct
4 Correct 1437 ms 47380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1746 ms 50064 KB Output is correct
2 Correct 1263 ms 53272 KB Output is correct
3 Correct 1813 ms 61128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1654 ms 65536 KB Output is correct
2 Correct 1325 ms 65536 KB Output is correct
3 Correct 1829 ms 65536 KB Output is correct
4 Correct 498 ms 65536 KB Output is correct