# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
94008 | vamaddur | Uzastopni (COCI15_uzastopni) | C++14 | 69 ms | 25380 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.
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <deque>
#include <string.h>
#include <sstream>
#include <bitset>
#include <math.h>
#include <assert.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
#define PI atan2(0, -1)
#define epsilon 1e-9
#define INF 5000000000000000000
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
int N, arr [10010];
vector<int> adjacency [10010], process [10010];
vector<pair<int, int>> ret [10010];
bitset<110> dp [10010][110];
void dfs(int curr){
for(int nexty : adjacency[curr]) dfs(nexty);
for(int i = 0; i < 100; i++) process[i] = vector<int>();
for(int nexty : adjacency[curr])
for(pair<int, int> lol : ret[nexty])
process[lol.f].pb(lol.s);
for(int lo = 99; lo > -1; lo--){
if(lo == arr[curr]){
dp[curr][lo] |= dp[curr][lo+1];
dp[curr][lo].set(lo);
}
else{
for(int hi : process[lo]){
if(lo <= arr[curr] && hi >= arr[curr]) continue;
dp[curr][lo] |= dp[curr][hi+1];
dp[curr][lo].set(hi);
}
}
if(arr[curr] >= lo)
for(int hi = 99; hi >= arr[curr]; hi--)
if(dp[curr][lo].test(hi))
ret[curr].pb(mp(lo, hi));
}
}
int main(){
//freopen("sort.in", "r", stdin); freopen("sort.out", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
cin >> N;
for(int i = 0; i < N; i++){ cin >> arr[i]; arr[i]--; }
for(int i = 1; i < N; i++){
int a, b; cin >> a >> b; a--; b--;
adjacency[a].pb(b);
}
dfs(0); cout << ret[0].size() << '\n';
return 0;
}
/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |