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

제출 #43918

#제출 시각아이디문제언어결과실행 시간메모리
43918WaschbarPaprike (COI18_paprike)C++17
100 / 100
207 ms17712 KiB
#include <bits/stdc++.h> #define ff first #define ss second using namespace std; const int MAXN = 1e5; int n, k, ans; int sp[MAXN+1]; vector < vector < int > > g(MAXN+1); long long DFS(int f, int p) { long long cnt = 0; vector < long long > v; cnt = sp[f]; for(int i = 0; i < g[f].size(); i++) { int to = g[f][i]; if(to == p) continue; long long x = DFS(to,f); cnt += x; v.push_back(x); } if(cnt <= k) return cnt; cnt = sp[f]; sort(v.begin(),v.end()); ans += v.size(); for(int i = 0; i < v.size(); i++) { if(cnt+v[i] <= k) {cnt += v[i]; ans--;} else break; } return cnt; } int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); cin >> n >> k; for(int i = 1; i <= n; i++) cin >> sp[i]; for(int i = 1; i < n; i++) { int x, y; cin >> x >> y; g[x].push_back(y); g[y].push_back(x); } DFS(1,0); cout << ans << endl; return 0; }

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

paprike.cpp: In function 'long long int DFS(int, int)':
paprike.cpp:17:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < g[f].size(); i++) {
                        ~~^~~~~~~~~~~~~
paprike.cpp:30:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < v.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...