Submission #1103402

# Submission time Handle Problem Language Result Execution time Memory
1103402 2024-10-20T19:35:46 Z codexistent Uzastopni (COCI15_uzastopni) C++14
160 / 160
19 ms 5972 KB
// testing

#include <bits/stdc++.h>
using namespace std;

#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(){
	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);

	cout<<(lp[1].size())*(rp[1].size())<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 2 ms 1108 KB Output is correct
7 Correct 2 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 2 ms 1108 KB Output is correct
11 Correct 10 ms 2020 KB Output is correct
12 Correct 12 ms 1888 KB Output is correct
13 Correct 11 ms 1876 KB Output is correct
14 Correct 19 ms 5972 KB Output is correct
15 Correct 16 ms 5972 KB Output is correct
16 Correct 16 ms 5972 KB Output is correct
17 Correct 15 ms 1876 KB Output is correct
18 Correct 12 ms 2060 KB Output is correct
19 Correct 10 ms 1876 KB Output is correct
20 Correct 10 ms 1876 KB Output is correct