# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
411115 | iANikzad | Uzastopni (COCI15_uzastopni) | C++14 | 113 ms | 30764 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;
#define pb push_back
#define F first
#define S second
#define debug(x) cerr<<#x<<" :"<<x<<"\n"
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define FAST ios_base::sync_with_stdio(false), cin.tie(), cout.tie();
#define int long long
typedef long long ll;
typedef long double ld;
const int maxn = 1e4 + 7;
const int maxk = 1e2 + 7;
const int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const int mlog = 20;
const int SQ = 400;
int a[maxn];
vector<int> adj[maxn], q[maxn];
vector<pii> s[maxn];
bitset<maxk> dp[maxn][maxk];
void dfs(int v)
{
for(int u : adj[v]) dfs(u);
for(int i = 1; i < maxk; i++)
q[i].clear();
for(int u : adj[v]) for(pii p : s[u]) q[p.F].pb(p.S);
for(int l = maxk - 1; l >= 1; l--)
{
if(l == a[v])
{
dp[v][l] |= dp[v][l + 1];
dp[v][l][l] = true;
}
else
{
for(int r : q[l])
{
if(a[v] < l || a[v] > r)
{
dp[v][l] |= dp[v][r + 1];
dp[v][l][r] = true;
}
}
}
for(int r = maxk - 1; r >= l; r--) if(dp[v][l][r] && a[v] >= l && a[v] <= r) s[v].pb({l, r});
}
}
int32_t main()
{
FAST;
int n; cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1;i < n; i++)
{
int u, v;
cin >> u >> v;
adj[u].pb(v);
}
dfs(1);
cout << s[1].size() << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |