Submission #625323

#TimeUsernameProblemLanguageResultExecution timeMemory
625323MinaRagy06Paprike (COI18_paprike)C++17
13 / 100
36 ms10128 KiB
#include <bits/stdc++.h> using namespace std; #define lesgooo ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define endl '\n' #define int long long vector<int> par, sum, sz; int n, x, y, k; int find(int u) {return par[u] = (u == par[u]? u : find(par[u]));} int unionn(int u, int v) { u = find(u), v = find(v); if (sum[u]+sum[v] > k) return 1; if (sz[u] < sz[v]) swap(u, v); sz[u]+=sz[v], par[v] = u, sum[u]+=sum[v]; return 0; } signed main() { lesgooo; cin >> n >> k; par.resize(n), sum.resize(n), sz.resize(n); for (int i =0 ; i < n; i++) cin >> sum[i], par[i] = i, sz[i] = 1; int ans =0 ; vector<vector<int>> edges; for (int i = 0; i < n-1; i++) cin >> x >> y, edges.push_back({--x, --y, sum[x]+sum[y]}); // sort(edges.begin(), edges.end(), [&](auto _a, auto _b) {return _a[2] < _b[2];}); for (int i = 0; i < n-1; i++) ans+=unionn(edges[i][0], edges[i][1]); cout << ans; 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...