# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
670731 | nonono | Uzastopni (COCI15_uzastopni) | C++17 | 86 ms | 32384 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"
#define SZ(x) (int)(x.size())
using namespace std;
typedef bitset<100> B ;
const int mxN = 1e4 + 2, mxM = 1e2;
int n, v[mxN];
B dp[mxN][mxM];
vector<vector<int>> adj(mxN);
void dfs(int u, int pre){
B b[mxM];
for(int v : adj[u]){
if(v == pre) continue ;
dfs(v, u);
for(int i = 0; i < mxM; i ++)
b[i] |= dp[v][i];
}
for(int i = mxM - 1; i >= 0; i --){
for(int j = i + 1; j < mxM; j ++){
if(b[i][j - 1]) b[i] |= b[j];
}
}
for(int i = 0; i <= v[u]; i ++){
for(int j = v[u]; j < mxM; j ++)
if(((v[u] - 1 >= 0 && b[i][v[u] - 1]) || (i == v[u])) &&
((v[u] + 1 < mxM && b[v[u] + 1][j]) || (j == v[u]))) dp[u][i][j] = 1;
}
}
signed main(){
#define file "uzastopni"
if(fopen(file".inp", "r")){
freopen(file".inp", "r", stdin);
freopen(file".out", "w", stdout);
}
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 0; i < n; i ++){
int x;
cin >> x;
v[i] = x - 1;
}
for(int i = 1; i < n; i ++){
int u, v;
cin >> u >> v;
u = u - 1;
v = v - 1;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(0, -1);
int result = 0;
for(int i = 0; i < mxM; i ++){
result += dp[0][i].count();
}
cout << result ;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |