Submission #29296

# Submission time Handle Problem Language Result Execution time Memory
29296 2017-07-19T01:46:13 Z 서규호(#1166) Dynamite (POI11_dyn) C++14
0 / 100
2243 ms 28632 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] && big == lev[x]+m){
		put++;
		cnt[par[x]] = m-1;
		return -Inf;
	}else if(big == -Inf){
		return -Inf;
	}else return big+1;
}

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,-1,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

dyn.cpp: In function 'int main()':
dyn.cpp:47:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&N,&M);
                      ^
dyn.cpp:49:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
                    ^
dyn.cpp:53:23: 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 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
4 Incorrect 0 ms 14032 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 14032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 14032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 14032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 14428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 15880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 306 ms 17464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 946 ms 20500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2079 ms 24920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2243 ms 28632 KB Output isn't correct
2 Halted 0 ms 0 KB -