Submission #1117672

#TimeUsernameProblemLanguageResultExecution timeMemory
1117672Hurryup_7735Paprike (COI18_paprike)C++17
100 / 100
56 ms30704 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define endl '\n' #define pb push_back #define speedyboy ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define all(x) x.begin() , x.end() #define F first #define S second #define pll pair<ll , ll> #define pss pair<string , string> #define YES cout << "YES" << endl; #define NO cout << "NO" << endl; const ll sz = 5e5 + 5 , INF = 1e8 , MOD = 998244353; ll a[sz]; bool used[sz]; vector<ll> g[sz]; ll n , m; ll dfs(ll n , ll u , ll &cursum){ cursum = a[n]; ll ans = 0; vector<ll> v; for(ll i : g[n]){ if(i != u){ ll changesum = 0; ans += dfs(i , n , changesum); v.pb(changesum); } } sort(all(v)); for(ll i = 0 ; i < v.size() ; i++){ if(cursum + v[i] > m){ ans++; } else{ cursum += v[i]; } } if(cursum > m){ ans++; } return ans; } ll i , j , k; void solve(){ cin >> n >> m; for(i = 1 ; i <= n ; i++){ cin >> a[i]; } for(i = 1 ; i < n ; i++){ ll u , v; cin >> u >> v; g[u].pb(v); g[v].pb(u); } ll cursum = 0; cout << dfs(1 , -1 , cursum) << endl; } signed main(){ speedyboy; ll t = 1; //cin >> t; while(t--){ solve(); } }

Compilation message (stderr)

paprike.cpp: In function 'long long int dfs(long long int, long long int, long long int&)':
paprike.cpp:37:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(ll 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...