# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
675189 | abcvuitunggio | Uzastopni (COCI15_uzastopni) | C++17 | 2 ms | 724 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 <iostream>
#include <bitset>
#include <vector>
#include <algorithm>
using namespace std;
bitset <101> dp[10001][101];
int n,a[101],u,v,res;
vector <int> ke[10001];
void dfs(int u){
dp[u][a[u]][a[u]]=1;
if (ke[u].empty())
return;
int pos=-1,pos2=1e9;
for (int i=0;i<ke[u].size();i++){
int v=ke[u][i];
dfs(v);
if (a[v]<=a[u])
pos=max(pos,i);
if (a[v]>=a[u])
pos2=min(pos2,i);
}
for (int it=pos2;it<ke[u].size();it++){
int v=ke[u][it];
for (int j=a[u];j<=100;j++)
if (!dp[u][a[u]][j])
for (int i=a[u]+1;i<=j;i++)
dp[u][a[u]][j]=dp[u][a[u]][j]|(dp[u][a[u]][i-1]&dp[v][i][j]);
}
for (int it=pos;it>=0;it--){
int v=ke[u][it];
for (int j=1;j<=a[u];j++)
if (!dp[u][j][a[u]])
for (int i=j;i<a[u];i++)
dp[u][j][a[u]]=dp[u][j][a[u]]|(dp[u][i+1][a[u]]&dp[v][j][i]);
}
for (int i=1;i<=a[u];i++)
for (int j=a[u];j<=100;j++)
dp[u][i][j]=dp[u][i][j]|(dp[u][i][a[u]]&dp[u][a[u]][j]);
}
int main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> n;
for (int i=1;i<=n;i++)
cin >> a[i];
for (int i=1;i<n;i++){
cin >> u >> v;
ke[u].push_back(v);
}
for (int i=1;i<=n;i++)
sort(ke[i].begin(),ke[i].end(),[](int i, int j){
return a[i]<a[j];
});
dfs(1);
int cnt=0;
for (int i=1;i<=100;i++)
for (int j=1;j<=100;j++)
cnt+=dp[1][i][j];
cout << cnt;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |