Submission #411122

#TimeUsernameProblemLanguageResultExecution timeMemory
411122sinamhdvUzastopni (COCI15_uzastopni)C++11
160 / 160
85 ms20040 KiB
// COCI15_uzastopni #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int mod = 1000 * 1000 * 1000 + 7; const int INF = 1e9 + 100; const ll LINF = 1e18 + 100; #ifdef DEBUG #define dbg(x) cout << #x << " = " << (x) << endl << flush; #define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; } #else #define dbg(x) ; #define dbgr(s, f) ; #endif #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define all(x) (x).begin(), (x).end() #define pb push_back #define mp make_pair #define fr first #define sc second #define endl '\n' #define MAXN 10100 #define MAXA 120 int n, val[MAXN]; vector<int> cld[MAXN]; bitset<MAXA> dp[MAXN][MAXA]; bitset<MAXA> ndp[MAXA]; void dfs(int v) { for (int u : cld[v]) dfs(u); FOR(i, 0, MAXA) ndp[i].reset(); for (int u : cld[v]) FOR(i, 0, MAXA) ndp[i] |= dp[u][i]; for (int l = MAXA - 1; l >= 0; l--) { FOR(r, l, MAXA - 1) { if (ndp[l][r]) { ndp[l] |= ndp[r + 1]; } } } for (int l = val[v]; l > 0; l--) if (l == val[v] || ndp[l][val[v] - 1]) { dp[v][l] |= ndp[val[v] + 1]; dp[v][l][val[v]] = 1; } } int32_t main(void) { fast_io; cin >> n; FOR(i, 1, n + 1) cin >> val[i]; FOR(i, 0, n - 1) { int x, y; cin >> x >> y; cld[x].pb(y); } dfs(1); int ans = 0; FOR(l, 0, MAXA) ans += dp[1][l].count(); cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...