This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
vector<ll> g[sz];
ll i , j , k;
void solve(){
ll n , m , sum = 0 , ans = 0;
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);
}
for(i = 1 ; i <= n ; i++){
if(sum + a[i] > m){
ans++;
sum = 0;
}
sum += a[i];
}
cout << ans << endl;
}
signed main(){
speedyboy;
ll t = 1;
//cin >> t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |