# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
626700 | MilosMilutinovic | Uzastopni (COCI15_uzastopni) | C++14 | 313 ms | 19136 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: wxhtzdy
* created: 11.08.2022 17:31:40
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<vector<int>> g(n);
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
--u; --v;
g[u].push_back(v);
g[v].push_back(u);
}
const int MAX = 105;
vector<vector<bitset<MAX>>> dp(n, vector<bitset<MAX>>(MAX));
function<void(int, int)> Dfs = [&](int v, int pr) {
dp[v][a[v]][a[v]] = 1;
for (int u : g[v]) {
if (u == pr) {
continue;
}
Dfs(u, v);
for (int l = 1; l < MAX; l++) {
for (int r = l; r < MAX; r++) {
if (l <= a[v] && a[v] <= r) {
continue;
}
if (dp[u][l][r]) {
dp[v][l][r] = 1;
}
}
}
}
for (int l = MAX - 1; l >= 1; l--) {
for (int r = l; r < MAX; r++) {
if (dp[v][l][r]) {
dp[v][l] |= dp[v][r + 1];
}
}
}
for (int l = 1; l < MAX; l++) {
for (int r = l; r < MAX; r++) {
if ((r < a[v] || a[v] < l) && dp[v][l][r]) {
dp[v][l][r] = 0;
}
}
}
};
Dfs(0, 0);
int ans = 0;
for (int i = 1; i < MAX; i++) {
for (int j = i; j < MAX; j++) {
if (dp[0][i][j]) {
ans += 1;
}
}
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |