Submission #603350

# Submission time Handle Problem Language Result Execution time Memory
603350 2022-07-24T04:04:56 Z Zanite Paprike (COI18_paprike) C++17
0 / 100
52 ms 21832 KB
#include <bits/stdc++.h>
using namespace std;

using pii	= pair<int, int>;
using ll	= long long;
using pll	= pair<ll, ll>;

#define fi	first
#define se	second

const int maxN	= 1e5 + 5;

int n;
ll k, h[maxN], sum[maxN];
vector<int> adj[maxN];

int dfs(int cur, int par) {
	int ret = 0;
	sum[cur] = h[cur];

	vector<int> spice;
	for (auto &nxt : adj[cur]) {
		if (nxt == par) continue;
		ret += dfs(nxt, cur);
		spice.push_back(sum[nxt]);
	}
	sort(spice.begin(), spice.end());
	for (int i = 0; i < spice.size(); i++) {
		if (sum[cur] + spice[i] >= k) ret++;
		else sum[cur] += spice[i];
	}
	return ret;
}

int main() {
	scanf("%d %lld", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &h[i]);
	}
	for (int u, v, i = 1; i < n; i++) {
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	printf("%d\n", dfs(1, 0));
}

Compilation message

paprike.cpp: In function 'int dfs(int, int)':
paprike.cpp:28:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |  for (int i = 0; i < spice.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~
paprike.cpp: In function 'int main()':
paprike.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  scanf("%d %lld", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
paprike.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%lld", &h[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
paprike.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 50 ms 21724 KB Output is correct
2 Correct 50 ms 21832 KB Output is correct
3 Correct 49 ms 21800 KB Output is correct
4 Correct 48 ms 21828 KB Output is correct
5 Correct 51 ms 21724 KB Output is correct
6 Correct 52 ms 21772 KB Output is correct
7 Correct 49 ms 21712 KB Output is correct
8 Incorrect 46 ms 21368 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -