# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
874957 | serifefedartar | Uzastopni (COCI15_uzastopni) | C++17 | 69 ms | 24504 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;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 10007;
const ll LOGN = 20;
const ll MAXN = 1e4 + 100;
vector<vector<int>> graph;
vector<pair<int,int>> possible[MAXN];
vector<int> border[105];
bitset<105> bs[MAXN][105];
int V[MAXN];
void dfs(int node) {
for (auto u : graph[node])
dfs(u);
for (int i = 0; i < 105; i++)
border[i].clear();
for (auto u : graph[node]) {
for (auto q : possible[u])
border[q.f].push_back(q.s);
}
for (int i = 104; i >= 1; i--) {
if (i == V[node]) {
bs[node][i] |= bs[node][i+1];
bs[node][i].set(i);
} else {
for (auto u : border[i]) {
if (u < V[node] || i > V[node]) {
bs[node][i] |= bs[node][u + 1];
bs[node][i].set(u);
}
}
}
for (int r = i; r <= 104; r++) {
if (bs[node][i].test(r) && V[node] >= i && V[node] <= r)
possible[node].push_back({i, r});
}
}
}
int main() {
fast
int N, A, B;
cin >> N;
for (int i = 1; i <= N; i++)
cin >> V[i];
graph = vector<vector<int>>(N+1, vector<int>());
for (int i = 1; i < N; i++) {
cin >> A >> B;
graph[A].push_back(B);
}
dfs(1);
cout << possible[1].size() << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |