# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
648741 | Adominator | Uzastopni (COCI15_uzastopni) | C++17 | 111 ms | 23796 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;
typedef long long ll;
#define ar array
#define vo vector
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
#define rep(i, a, b) for(ll i=(a); i<(b); i++)
#define repd(i, a, b) for(ll i=(a); i>=(b); i--)
const int mxn=1e4+1, mxv=101;
vo<int> al[mxn], it[mxv];
bitset<mxv> memo[mxn][mxv];
vo<ar<int, 2>> itv[mxn];
int n, A[mxn];
void dp(int v) {
for(auto i: al[v])
dp(i);
rep(i, 0, mxv)
it[i].clear();
for(auto i: al[v])
for(auto [a, b]: itv[i])
it[a].pb(b);
repd(i, mxv-1, 1) {
if(A[v]==i) {
memo[v][i]|=memo[v][i+1];
memo[v][i][i]=1;
}
else {
for(auto j: it[i])
if(j<A[v]||i>A[v]) {
memo[v][i]|=memo[v][j+1];
memo[v][i][j]=1;
}
}
repd(j, mxv-1, i)
if(memo[v][i][j]&&A[v]>=i&&A[v]<=j)
itv[v].pb({i, j});
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
rep(i, 0, n)
cin >> A[i];
rep(i, 0, n-1) {
int a, b;
cin >> a >> b, --a, --b;
al[a].pb(b);
}
dp(0);
cout << sz(itv[0]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |