# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
39435 | adamczh1 | Uzastopni (COCI15_uzastopni) | C++14 | 0 ms | 1840 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define SIZE(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define ff first
#define ss second
inline ll readi(){
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int N;
int V[10001];
vector<int> adj[10001];
bitset<101> bs[10001][101]; // possible L for each R
vector<int> s[10001][101];
void dfs(int cur){
for(int v:adj[cur]){
dfs(v);
}
for(int i=1;i<=100;i++){
if(i==V[cur]) bs[cur][i].set(i), bs[cur][i]|=bs[cur][i-1];
for(int v:adj[cur])
for(int j:s[v][i]){
bs[cur][i].set(j);
bs[cur][i]|=bs[cur][j-1];
}
for(int j=1;j<=i;j++)
if(bs[cur][i][j] && V[cur]>=j && V[cur]<=i)
s[cur][i].push_back(j);
}
}
int main(){
N=readi();
for(int i=1; i<=N; i++){
V[i]=readi();
}
for(int i=1; i<N; i++){
int A=readi(),B=readi();
adj[A].push_back(B);
}
dfs(1);
int ans=0;
for(int r=V[1];r<=100;r++){
ans+=SIZE(s[1][r]);
}
cout<<ans<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |