제출 #1117601

#제출 시각아이디문제언어결과실행 시간메모리
1117601vjudge1Paprike (COI18_paprike)C++17
13 / 100
40 ms13136 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld double const int INF = 1e18; const int mod = 12345; const int sz = 3e6 + 5; int n , k , dp[sz]; vector < vector < int > > adj; vector < bool > vis(sz , false); int ans = 0 , sum = 0; void dfs(int v){ vis[v] = 1; sum += dp[v]; if(sum > k){ ans++; sum = dp[v]; } for(int u : adj[v]){ if(!vis[u]) dfs(u); } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; adj.resize(n + 1); for(int i = 1;i <= n;i++) cin >> dp[i]; int u[n] , v[n]; for(int i = 0;i < n - 1;i++){ cin >> u[i] >> v[i]; adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); } dfs(1); cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...