# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
25640 | szawinis | Uzastopni (COCI15_uzastopni) | C++14 | 206 ms | 25336 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.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (1e4)+2, MAXK = 102;
int n, a[MAXN];
vector<int> g[MAXN], q[MAXK];
vector<pair<int,int> > s[MAXN];
bitset<MAXK> dp[MAXN][MAXK];
void dfs(int u) {
for(int v: g[u]) dfs(v);
for(int i = 1; i < MAXK; i++) q[i].clear();
for(int v: g[u]) {
for(auto p: s[v]) q[p.first].push_back(p.second);
}
for(int l = MAXK-1; l >= 1; l--) {
if(l == a[u]) {
dp[u][l] |= dp[u][l+1];
dp[u][l][l] = true;
} else for(int r: q[l]) {
if(a[u] < l || a[u] > r) {
dp[u][l] |= dp[u][r+1];
dp[u][l][r] = true;
}
}
for(int r = MAXK-1; r >= l; r--) {
if(dp[u][l][r] && a[u] >= l && a[u] <= r) s[u].emplace_back(l, r);
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1, u, v; i < n; i++) {
cin >> u >> v;
g[u].push_back(v);
}
dfs(1);
cout << s[1].size();
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |