제출 #732766

#제출 시각아이디문제언어결과실행 시간메모리
732766bgnbvnbvPaprike (COI18_paprike)C++14
100 / 100
62 ms21068 KiB
#include<bits/stdc++.h> #define TASKNAME "codeforce" #define pb push_back #define pli pair<int,int> #define fi first #define se second #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); using namespace std; using ll=long long; const ll maxN=2e5; const ll inf=1e18; const ll mod=1e9+7; ll res=0; vector<ll>g[maxN]; ll ans[maxN]; ll h[maxN],k; void dfs(ll u=1,ll p=0) { vector<ll>vec; for(int v:g[u]) { if(v!=p) { dfs(v,u); vec.pb(ans[v]); res++; } } sort(vec.begin(),vec.end()); ans[u]=h[u]; for(int i=0;i<vec.size();i++) { if(ans[u]+vec[i]<=k) { ans[u]+=vec[i]; res--; } else break; } } ll n; void solve() { cin >> n>> k; for(int i=1;i<=n;i++) cin >> h[i]; for(int i=1;i<n;i++) { ll u,v; cin >> u >> v; g[u].pb(v); g[v].pb(u); } dfs(); //for(int i=1;i<=n;i++) cout << ans[i] <<' '; cout << res; } int main() { fastio //freopen(TASKNAME".INP","r",stdin); //freopen(TASKNAME".OUT","w",stdout); solve(); }

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

paprike.cpp: In function 'void dfs(ll, ll)':
paprike.cpp:31:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(int i=0;i<vec.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...