(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #454250

#TimeUsernameProblemLanguageResultExecution timeMemory
454250HillcrestEnigmaPaprike (COI18_paprike)C++17
100 / 100
91 ms19084 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #pragma GCC optimize("Ofast") #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() /* #define endl '\n' */ #define indexed_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; using vpii = vector<pair<int, int>>; const int MOD = 1e9+7; const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, -1, 0, 1}; int n, k, a, b; int ans = 0; int h[100000] = {0}; vi graph[100000]; int dfs(int v, int p) { vi spy; /* cout << v << ": "; */ /* for (int c:graph[v]) cout << c << " "; */ /* cout << endl; */ for (int c:graph[v]) if (c != p) spy.push_back(dfs(c, v)); sort(all(spy)); int res = h[v]; for (int i=0; i<spy.size(); i++) { if (res + spy[i] > k) { ans += spy.size() - i; return res; } res += spy[i]; } return res; } void _main() { cin >> n >> k; for (int i=0; i<n; i++) { cin >> h[i]; } for (int i=0; i<n-1; i++) { cin >> a >> b; --a; --b; graph[a].push_back(b); graph[b].push_back(a); } dfs(0, -1); cout << ans << endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); _main(); return 0; }

Compilation message (stderr)

paprike.cpp: In function 'int dfs(int, int)':
paprike.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for (int i=0; i<spy.size(); i++) {
      |                   ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...