(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.

제출 #48498

#제출 시각아이디문제언어결과실행 시간메모리
48498WLZPaprike (COI18_paprike)C++17
100 / 100
93 ms29632 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> ii; typedef long long ll; const int INF = 1e9; const int MAXN = 1e5 + 5; const ll LINF = 1e18; const double pi = acos(-1); const double EPS = 1e-9; template <class T> using MinPQ = priority_queue<T, vector<T>, greater<T>>; template <class T> using MaxPQ = priority_queue<T>; int n; ll k; int ops; vector<ll> a; vector< vector<int> > g; bitset<MAXN> used; vector<int> p; vector<int> v; vector<int> h; ll preCalc(int u, int par) { p[u] = par; vector <ll> children; ll ans = a[u]; for (int& x : g[u]) { if (x != par) { children.push_back(preCalc(x, u)); ans += children.back(); } } sort(children.begin(),children.end()); int pos = (int)(children.size() - 1); while (ans > k) { ans -= children[pos]; ops ++; pos --; } return ans; } int main() { #ifdef DEBUG //freopen("in.txt", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); scanf("%d %lld", &n, &k); p.assign(n, -1); g.assign(n, vector<int>()); a.assign(n, 0); for (int i = 0; i < n; i++) scanf("%lld", &a[i]); for (int i = 0; i < n - 1; i++) { int x, y; scanf("%d %d", &x, &y); --x; --y; g[x].emplace_back(y); g[y].emplace_back(x); } ops = 0; preCalc(0, -1); printf("%d\n", ops); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

paprike.cpp: In function 'int main()':
paprike.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %lld", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~~~~
paprike.cpp:54:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
                                 ~~~~~^~~~~~~~~~~~~~~
paprike.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &x, &y); --x; --y;
         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...