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

제출 #1117868

#제출 시각아이디문제언어결과실행 시간메모리
1117868vjudge1Paprike (COI18_paprike)C++17
0 / 100
1018 ms1048576 KiB
// author - alimammadzade #include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; int p[N]; int _find(int u) { return (p[u] < 0 ? u : p[u] = _find(p[u])); } void _union(int u, int v) { p[u] += p[v]; p[v] = u; } signed main() { cin.tie(nullptr)->sync_with_stdio(0); // system("cls"), freopen("in.txt", "r", stdin); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> p[i]; p[i] = -p[i]; } int res = 0; vector<array<int, 2>> e(n - 1); for (auto& [u, v] : e) { cin >> u >> v; int pu = _find(u), pv = _find(v); if (pu != pv and -p[pu] - p[pv] <= k) _union(pu, pv); res += (p[pv] != pu); } cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...