Submission #418022

# Submission time Handle Problem Language Result Execution time Memory
418022 2021-06-04T21:25:37 Z JerryLiu06 Uzastopni (COCI15_uzastopni) C++17
160 / 160
24 ms 4340 KB
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
using db = double;
using str = string;
 
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
 
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
 
#define mp make_pair
#define f first
#define s second
 
#define sz(x) (int)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front
 
#define lb lower_bound
#define ub upper_bound
 
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define EACH(a,x) for (auto& a: x)
 
const int MOD = 1e9 + 7;
const int MXN = 1e5 + 10;
const int MXV = 101;
const ll INF = 1e18;

int N, V[MXN]; vi child[MXN]; bitset<MXV> low[MXN], high[MXN]; // # of possible lowests, highests

bitset<MXV> LOW[MXV], HIGH[MXV]; // LOW[C1][C2] means C2 must be the lowest, with C1 as the highest

void solve(int X) {
    low[X][V[X]] = high[X][V[X]] = 1; EACH(C, child[X]) solve(C);

    FOR(i, 1, MXV) LOW[i].reset(), HIGH[i].reset();

    EACH(C, child[X]) FOR(i, 1, MXV) if (low[C][i]) FOR(j, 1, MXV) if (high[C][j]) {
        if (j < V[X]) LOW[j][i] = 1; if (i > V[X]) HIGH[i][j] = 1;
    }
    ROF(i, 2, V[X] + 1) if (low[X][i]) low[X] |= LOW[i - 1];

    FOR(i, V[X], MXV - 1) if (high[X][i]) high[X] |= HIGH[i + 1];
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> N; FOR(i, 1, N + 1) cin >> V[i]; 

    F0R(i, N - 1) { int A, B; cin >> A >> B; child[A].pb(B); }

    solve(1); cout << low[1].count() * high[1].count();
}

Compilation message

uzastopni.cpp: In function 'void solve(int)':
uzastopni.cpp:60:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   60 |         if (j < V[X]) LOW[j][i] = 1; if (i > V[X]) HIGH[i][j] = 1;
      |         ^~
uzastopni.cpp:60:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   60 |         if (j < V[X]) LOW[j][i] = 1; if (i > V[X]) HIGH[i][j] = 1;
      |                                      ^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2672 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 11 ms 3304 KB Output is correct
12 Correct 10 ms 3276 KB Output is correct
13 Correct 11 ms 3276 KB Output is correct
14 Correct 12 ms 4332 KB Output is correct
15 Correct 12 ms 4340 KB Output is correct
16 Correct 14 ms 4340 KB Output is correct
17 Correct 24 ms 3316 KB Output is correct
18 Correct 15 ms 3276 KB Output is correct
19 Correct 10 ms 3196 KB Output is correct
20 Correct 17 ms 3148 KB Output is correct