Submission #1319062

#TimeUsernameProblemLanguageResultExecution timeMemory
1319062ee23b179_cpUzastopni (COCI15_uzastopni)C++20
160 / 160
54 ms24132 KiB
#include<bits/stdc++.h>
using namespace std;

// define

#define execute cerr << " Time: " << fixed << setprecision(6) << (1.0 * clock() / CLOCKS_PER_SEC) << "s\n";
#define ll long long
#define ld double
#define ii pair<int,int>
#define se second
#define fi first
#define iii pair<int,ii>
#define all(v) v.begin(),v.end()
#define bit(x,i) (((x)>>(i))&1LL)
#define flip(x,i) ((x)^(1LL<<(i)))
#define ms(d,x) memset(d,x,sizeof(d))
#define sitingfake 1
#define orz 1
#define exist __exist
#define ends __ends
#define visit visited
#define left __left
#define right __right

//constant

const ll mod = 1e9 + 7;
const long long linf = 4557430888798830399;
const int inf = 1061109567;
const int maxarr = 1e6 + 5;
int dx[] = {0 , -1 , 0 , 1};
int dy[] = {-1 , 0 , 1 , 0};

template<typename T> bool maximize(T &a, const T &b)
{
    if(a < b) {a = b; return 1;}
    return 0;
}

template<typename T> bool minimize(T &a, const T &b)
{
    if(a > b) {a = b; return 1;}
    return 0;
}

inline void Plus(ll & a ,ll b)
{
    b %= mod;
    a += b;
    if(a >= mod) a -= mod;
    if(a < 0) a += mod;
    return;
}

inline void Mul(ll & a, ll b)
{
    a %= mod; b %= mod;
    a *= b;
    a %= mod;
    return;
}

//code

const int maxn = 1e4 + 7;

int n;

vector <int> a[maxn];

int val[maxn];

vector <int> Q[101];
vector <ii> s[maxn];

bitset <101> B[maxn][101];

void dfs(int u , int p)
{
    for(int v : a[u])
    {
        if(v != p)
        {
            dfs(v , u);
        }
    }

    for(int i = 1; i <= 100; i++) Q[i].clear();

    for(int v : a[u])
    {
        if(v != p)
        {
            for(ii it : s[v])
            {
                Q[it.fi].push_back(it.se);
            }
        }
    }

    for(int left = 100; left >= 1; left--)
    {
        if(left == val[u])
        {
            B[u][left] |= B[u][left + 1];
            B[u][left].set(left);
        }
        else
        {
            for(int right : Q[left])
            {
                if(right < val[u] || left > val[u])
                {
                    B[u][left] |= B[u][right + 1];
                    B[u][left].set(right);
                }
            }
        }

        if(left <= val[u])
        {
            for(int right = 100; right >= left; right--)
            {
                if(left <= val[u] && val[u] <= right && B[u][left][right])
                {
                    s[u].push_back(ii(left , right));
                }
            }
        }
    }
}

void solve(void)
{
    cin >> n;

    for(int i = 1; i <= n; i++) cin >> val[i];

    for(int i = 1; i < n; i++)
    {
        int u , v;
        cin >> u >> v;
        a[u].push_back(v);
        a[v].push_back(u);
    }

    dfs(1 , -1);

    cout << s[1].size();
}
/**
**/
signed main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   #define task ""

   if(fopen(task".inp","r"))
   {
       freopen(task".inp","r",stdin);
       freopen(task".out","w",stdout);
   }

   int tc; tc = 1;

   while(tc--) solve();

   //execute;
}

Compilation message (stderr)

uzastopni.cpp: In function 'int main()':
uzastopni.cpp:163:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  163 |        freopen(task".inp","r",stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
uzastopni.cpp:164:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  164 |        freopen(task".out","w",stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...