Submission #44211

# Submission time Handle Problem Language Result Execution time Memory
44211 2018-03-30T14:21:12 Z imaxblue Dynamite (POI11_dyn) C++17
100 / 100
1937 ms 43256 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 d[300005], u[300005];
vector<int> v[300005];
void dfs(int N, int P){
    block[N]=1;
    need[N]=0;
    u[N]=d[N];
    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);
        u[N]|=u[v[N][l]];
    }
    if (-block[N]>=need[N]){
        need[N]=-1;
        u[N]=0;
        return;
    }
    if (u[N]==0){
        block[N]=0;
        need[N]=-1;
        return;
    }
    if (need[N]==mid || P==-1){
        c++;
        u[N]=0;
        //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;
    }
    //cout << c << endl;
    return lo;
}
int main(){
    scan(n); scan(k);
    fox1(l, n) scanf("%i", &d[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:38:9:
     fox(l, v[N].size()){
         ~~~~~~~~~~~~~~            
dyn.cpp:38:5: note: in expansion of macro 'fox'
     fox(l, v[N].size()){
     ^~~
dyn.cpp: In function 'int main()':
dyn.cpp:78:33: warning: format '%i' expects argument of type 'int*', but argument 2 has type 'bool*' [-Wformat=]
     fox1(l, n) scanf("%i", &d[l]);
                            ~~~~~^
dyn.cpp:78:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fox1(l, n) scanf("%i", &d[l]);
                ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7544 KB Output is correct
2 Correct 9 ms 7544 KB Output is correct
3 Correct 8 ms 7544 KB Output is correct
4 Correct 9 ms 7544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7612 KB Output is correct
2 Correct 9 ms 7612 KB Output is correct
3 Correct 8 ms 7680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7680 KB Output is correct
2 Correct 9 ms 7680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7680 KB Output is correct
2 Correct 8 ms 7680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 8220 KB Output is correct
2 Correct 60 ms 9096 KB Output is correct
3 Correct 46 ms 9720 KB Output is correct
4 Correct 71 ms 11608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 12056 KB Output is correct
2 Correct 197 ms 13616 KB Output is correct
3 Correct 250 ms 14992 KB Output is correct
4 Correct 214 ms 18320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 273 ms 18448 KB Output is correct
2 Correct 343 ms 19804 KB Output is correct
3 Correct 392 ms 20772 KB Output is correct
4 Correct 395 ms 26472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 805 ms 29768 KB Output is correct
2 Correct 979 ms 32292 KB Output is correct
3 Correct 1592 ms 38392 KB Output is correct
4 Correct 1475 ms 38396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1662 ms 38396 KB Output is correct
2 Correct 1289 ms 38396 KB Output is correct
3 Correct 1848 ms 38796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1706 ms 41620 KB Output is correct
2 Correct 1295 ms 41620 KB Output is correct
3 Correct 1937 ms 43256 KB Output is correct
4 Correct 665 ms 43256 KB Output is correct