# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
29298 | 2017-07-19T01:48:51 Z | suhgyuho_william | Dynamite (POI11_dyn) | C++14 | 2393 ms | 29840 KB |
#include <bits/stdc++.h> #include <unistd.h> #define pii pair<int,int> #define pll pair<lld,lld> #define pb push_back #define next nextt #define left leftt #define right rightt #define lld long long #define Inf 1000000000 #define Linf 1000000000000000000LL #define get gett using namespace std; int N,M,ans; int a[300002],par[300002],lev[300002]; int cnt[300002]; bool check[300002]; vector<int> edge[300002]; int m,put; int dfs(int x){ check[x] = true; vector<int> tmp; int big = -Inf; for(auto &i : edge[x]){ if(check[i]) continue; lev[i] = lev[x]+1; par[i] = x; big = max(big,dfs(i)); } if(a[x] == 1) big = max(big,lev[x]); cnt[par[x]] = max(cnt[par[x]],cnt[x]-1); if(big <= lev[x]+cnt[x]-1) return -Inf; if(big == lev[x]+m){ put++; cnt[par[x]] = m; return -Inf; }else if(big == -Inf){ return -Inf; }else return big; } int main(){ //freopen("input.txt","r",stdin); scanf("%d %d",&N,&M); for(int i=1; i<=N; i++){ scanf("%d",&a[i]); } for(int i=1; i<N; i++){ int x,y; scanf("%d %d",&x,&y); edge[x].pb(y); edge[y].pb(x); } int l,r; l = 0; r = N-1; while(l <= r){ m = (l+r)/2; memset(check,0,sizeof(check)); memset(cnt,0,sizeof(cnt)); put = 0; if(dfs(1) != -Inf) put++; if(put <= M){ ans = m; r = m-1; }else l = m+1; } printf("%d\n",ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 14032 KB | Output is correct |
2 | Correct | 3 ms | 14032 KB | Output is correct |
3 | Correct | 0 ms | 14032 KB | Output is correct |
4 | Correct | 3 ms | 14032 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 14032 KB | Output is correct |
2 | Correct | 0 ms | 14032 KB | Output is correct |
3 | Correct | 0 ms | 14032 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 14032 KB | Output is correct |
2 | Correct | 0 ms | 14032 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 14032 KB | Output is correct |
2 | Correct | 6 ms | 14032 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 14428 KB | Output is correct |
2 | Correct | 39 ms | 14824 KB | Output is correct |
3 | Correct | 43 ms | 14956 KB | Output is correct |
4 | Correct | 63 ms | 15872 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 63 ms | 15880 KB | Output is correct |
2 | Correct | 123 ms | 16408 KB | Output is correct |
3 | Correct | 249 ms | 16540 KB | Output is correct |
4 | Correct | 226 ms | 18224 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 239 ms | 17464 KB | Output is correct |
2 | Correct | 289 ms | 17468 KB | Output is correct |
3 | Correct | 446 ms | 17200 KB | Output is correct |
4 | Correct | 549 ms | 20256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 986 ms | 20500 KB | Output is correct |
2 | Correct | 1169 ms | 21964 KB | Output is correct |
3 | Correct | 1043 ms | 26156 KB | Output is correct |
4 | Correct | 1363 ms | 26160 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2393 ms | 24920 KB | Output is correct |
2 | Correct | 1799 ms | 24344 KB | Output is correct |
3 | Correct | 1753 ms | 26684 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2296 ms | 28632 KB | Output is correct |
2 | Correct | 1733 ms | 24348 KB | Output is correct |
3 | Correct | 1953 ms | 29840 KB | Output is correct |
4 | Correct | 789 ms | 25488 KB | Output is correct |