# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
527338 | colazcy | Uzastopni (COCI15_uzastopni) | C++11 | 6 ms | 2000 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 <cstdio>
#include <cassert>
#include <vector>
#include <bitset>
#include <algorithm>
#define let const auto
#define rep(name,beg,end) for(auto lim_##name = end,name = beg;name <= lim_##name;name++)
#define per(name,beg,end) for(auto lim_##name = end,name = beg;name >= lim_##name;name--)
#define repn(lim) for(auto REPN_LIM = lim,REPN = 1;REPN <= REPN_LIM;REPN++)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define trace() debug("Line : %d, Function : %s\n",__LINE__,__FUNCTION__)
using ll = long long;
constexpr int maxn = 1e4 + 10,maxm = 103;
std::bitset<maxm> L[maxn],R[maxn];
int n,val[maxn];
std::vector<int> G[maxn];
void dp(const int u){
L[u].set(val[u]);
R[u].set(val[u]);
for(let v : G[u])dp(v);
std::sort(G[u].begin(),G[u].end(),[](const int x,const int y){return val[x] < val[y];});
for(let v : G[u])
if(val[v] > val[u] && ((R[u] << 1) & L[v]).any())R[u] |= R[v];
std::reverse(G[u].begin(),G[u].end());
for(let v : G[u])
if(val[v] < val[u] && ((L[u] >> 1) & R[v]).any())L[u] |= L[v];
}
int main(){
// std::freopen("uzastopni.in","r",stdin);
// std::freopen("uzastopni.out","w",stdout);
std::scanf("%d",&n);
rep(i,1,n)std::scanf("%d",val + i);
repn(n - 1){
int u,v; std::scanf("%d %d",&u,&v);
G[u].push_back(v);
}
dp(1);
std::printf("%d\n",(int)(L[1].count() * R[1].count()));
// std::fclose(stdin);
// std::fclose(stdout);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |