Submission #120427

# Submission time Handle Problem Language Result Execution time Memory
120427 2019-06-24T12:47:16 Z popovicirobert Dynamite (POI11_dyn) C++14
0 / 100
1964 ms 29660 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);
		cnt += (dp1[1] >= 0);
		if(cnt > m) {
			res += step;
		}
	}

	cout << res + 1;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 7424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 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 9 ms 7580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 8036 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 10104 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 147 ms 12344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 771 ms 16744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1964 ms 23376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1741 ms 29660 KB Output isn't correct
2 Halted 0 ms 0 KB -