# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
527338 | colazcy | Uzastopni (COCI15_uzastopni) | C++11 | 6 ms | 2000 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |