Submission #29291

# Submission time Handle Problem Language Result Execution time Memory
29291 2017-07-19T01:38:54 Z 서규호(#1166) Dynamite (POI11_dyn) C++14
0 / 100
2189 ms 28628 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 3 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 3 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 9 ms 14428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 15880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 289 ms 17464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 906 ms 20500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2189 ms 24920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1819 ms 28628 KB Output isn't correct
2 Halted 0 ms 0 KB -