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

Submission #1117719

#TimeUsernameProblemLanguageResultExecution timeMemory
1117719vjudge1Paprike (COI18_paprike)C++17
0 / 100
1064 ms12104 KiB
#include "bits/stdc++.h" #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ll long long #define pb push_back #define in insert #define F first #define S second #define vll vector<ll> #define all(v) v.begin(),v.end() #define endl '\n' #define pii pair<ll,ll> using namespace std; const ll INF =1e18, mod = 1e9 + 7, N = 1e5 + 5; ll gcd(ll a, ll b){ if(b == 0){ return a; } return gcd(b, a % b); } ll lcm(ll a, ll b){ return (a / gcd(a,b)) * b; } vector<ll>g[N]; ll used[N]; ll sum = 0; ll n,k; ll a[N]; ll cnt = 0; void dfs(ll s){ used[s] = 1; for(auto i : g[s]){ if(!used[i]){ if(a[i] + sum <= k){ sum += a[i]; } else{ cnt++; sum = a[i]; } dfs(i); } } } void solve(){ cin >> n >> k; for(int i = 1; i <= n; i++){ cin >> a[i]; } ll x,y; for(int i = 0; i < n - 1; i++){ cin >> x >> y; g[x].pb(y); g[y].pb(x); } ll mini = INT_MAX; for(int i = 1; i <= n; i++){ sum = a[i]; cnt = 0; for(int i =1; i <= n; i++){ used[i] = 0; } dfs(i); mini = min(mini, cnt); } cout << mini <<endl; } int main(){ fast; ll t = 1; // cin >> t; while(t--){ solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...