Submission #120422

# Submission time Handle Problem Language Result Execution time Memory
120422 2019-06-24T12:43:13 Z popovicirobert Dynamite (POI11_dyn) C++14
0 / 100
1944 ms 33800 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lsb(x) (x & (-x)) 

using namespace std;

const int INF = 1e9;
const int MAXN = (int) 3e5;

vector <int> g[MAXN + 1];
int dyn[MAXN + 1];
int dp1[MAXN + 1]; // cel mai departat TNT neexplodat
int dp2[MAXN + 1]; // cel mai apropiat nod selectat
int cnt;

void dfs(int nod, int par, int len) {
	dp1[nod] = (dyn[nod] ? 0 : -INF);
	for(auto it : g[nod]) {
		if(it != par) {
			dfs(it, nod, len);
			dp1[nod] = max(dp1[nod], dp1[it] + 1);
			dp2[nod] = max(dp2[nod], dp2[it] - 1);
		}
	}

	if(dp1[nod] <= dp2[nod]) dp1[nod] = -INF;
	if(dp1[nod] >= len) {
		dp1[nod] = -INF;
		cnt++;
		dp2[nod] = len;
	}
}

int main() {
	//ifstream cin("A.in");
	//ofstream cout("A.out");
	int i, n, m;
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	
	cin >> n >> m;

	for(i = 1; i <= n; i++) {
		cin >> dyn[i];
	}

	for(i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}

	int res = 0;
	for(int step = 1 << 18; step; step >>= 1) {
		cnt = 0;
		dfs(1, 0, res + step);
		if(cnt > m) {
			res += step;
		}
	}

	cout << res + 1;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 7424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 7424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 7424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 7436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 8064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 71 ms 10556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 209 ms 13276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 942 ms 19292 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1944 ms 27496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1738 ms 33800 KB Output isn't correct
2 Halted 0 ms 0 KB -