# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1083313 | f0rizen | Uzastopni (COCI15_uzastopni) | C++17 | 71 ms | 23952 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;
using ll = long long;
const int inf = 1e9 + 7;
const ll infll = 1e18;
template<typename T>
istream &operator>>(istream &is, vector<T> &a) {
for (auto &i : a) {
is >> i;
}
return is;
}
const int N = 100;
vector<int> a;
vector<vector<int>> g;
vector<vector<bitset<N>>> dp;
vector<vector<pair<int, int>>> s;
void dfs(int v) {
for (auto u : g[v]) {
dfs(u);
}
vector<vector<int>> R(N);
for (auto u : g[v]) {
for (auto [l, r] : s[u]) {
R[l].push_back(r);
}
}
for (int i = N - 1; i >= 0; --i) {
if (i == a[v]) {
dp[v][i][i] = 1;
dp[v][i] |= dp[v][i + 1];
continue;
}
for (auto j : R[i]) {
if (!(i <= a[v] && a[v] <= j)) {
dp[v][i][j] = 1;
dp[v][i] |= dp[v][j + 1];
}
}
}
for (int i = 0; i < N; ++i) {
for (int j = i; j < N; ++j) {
if (i <= a[v] && a[v] <= j && dp[v][i][j]) {
s[v].push_back({i, j});
}
}
}
}
int32_t main() {
#ifdef LOCAL
freopen("/tmp/input.txt", "r", stdin);
#else
ios::sync_with_stdio(false);
cin.tie(nullptr);
#endif
int n;
cin >> n;
a.resize(n);
cin >> a;
for (auto &i : a) {
--i;
}
g.resize(n);
for (int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
--u, --v;
g[u].push_back(v);
}
dp.resize(n, vector<bitset<N>>(N));
s.resize(n);
dfs(0);
cout << s[0].size() << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |