Submission #1117590

#TimeUsernameProblemLanguageResultExecution timeMemory
1117590vjudge1Paprike (COI18_paprike)C++17
11 / 100
22 ms592 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 = 20; int n , k , dp[sz]; vector < vector < int > > adj; vector < bool > vis(sz , 20); int sum = 0; void dfs(int v){ sum += dp[v]; vis[v] = 1; for(int u : adj[v]){ if(!vis[u]){ dfs(u); } } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; 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]; } int ans = INF; for(int bit = 0;bit < pow(2 , n) - 1;bit++){ vis.assign(sz , false); adj.clear(); adj.resize(n + 1); int cnt = 0; for(int i = 0;i < n - 1;i++){ if((1 << i) & bit){ adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); } else{ cnt++; } } int tot[2]; tot[0] = tot[1] = 0; for(int i = 1;i <= n;i++){ if(!vis[i]){ tot[0]++; dfs(i); if(k >= sum) tot[1]++; sum = 0; } } if(tot[1] == tot[0]){ ans = min(ans , cnt); } } 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...