Submission #411119

# Submission time Handle Problem Language Result Execution time Memory
411119 2021-05-24T11:58:52 Z sinamhdv Uzastopni (COCI15_uzastopni) C++11
136 / 160
99 ms 38340 KB
// 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];

void dfs(int v)
{
	bitset<MAXA> ndp[MAXA];
	for (int u : cld[v])
	{
		dfs(u);
		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;
		}

//	dbg(v);
//	FOR(i, 0, MAXA) dbg(ndp[i]);
//	FOR(i, 0, MAXA) dbg(dp[v][i]);
}

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 time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 2 ms 716 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 2 ms 716 KB Output is correct
6 Correct 2 ms 844 KB Output is correct
7 Correct 2 ms 844 KB Output is correct
8 Correct 2 ms 844 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 83 ms 19500 KB Output is correct
12 Correct 89 ms 19724 KB Output is correct
13 Correct 84 ms 19544 KB Output is correct
14 Runtime error 92 ms 38328 KB Memory limit exceeded
15 Runtime error 99 ms 38340 KB Memory limit exceeded
16 Runtime error 92 ms 38336 KB Memory limit exceeded
17 Correct 85 ms 19576 KB Output is correct
18 Correct 99 ms 19544 KB Output is correct
19 Correct 91 ms 19372 KB Output is correct
20 Correct 84 ms 19352 KB Output is correct