# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
964713 | pcc | Uzastopni (COCI15_uzastopni) | C++17 | 12 ms | 6060 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;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const int mxn = 1e4+10;
int N;
int arr[mxn];
vector<int> tree[mxn];
vector<int> lp[mxn],rp[mxn];
vector<int> lop[110],rop[110];
bitset<110> dl,dr;
void dfs(int now){
for(auto nxt:tree[now]){
dfs(nxt);
}
for(auto &i:lop)i.clear();
for(auto &i:rop)i.clear();
for(auto nxt:tree[now]){
for(auto &i:lp[nxt]){
for(auto &j:rp[nxt]){
assert(i<=j);
if(i>arr[now])rop[i].push_back(j);
if(j<arr[now])lop[j].push_back(i);
}
}
}
dl.reset();
dr.reset();
dl[arr[now]] = dr[arr[now]] = 1;
for(int i = arr[now];i+1<110;i++){
if(dr[i]){
rp[now].push_back(i);
for(auto &j:rop[i+1])dr[j] = 1;
}
}
for(int i = arr[now];i>0;i--){
if(dl[i]){
lp[now].push_back(i);
for(auto &j:lop[i-1])dl[j] = 1;
}
}
return;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N;
for(int i = 1;i<=N;i++)cin>>arr[i];
for(int i = 1;i<N;i++){
int a,b;
cin>>a>>b;
tree[a].push_back(b);
}
dfs(1);
/*
for(int i = 1;i<=N;i++){
cout<<i<<":"<<endl;
for(auto &j:lp[i])cout<<j<<',';cout<<endl;
for(auto &j:rp[i])cout<<j<<',';cout<<endl;
}
*/
cout<<(lp[1].size())*(rp[1].size())<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |