답안 #47716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47716 2018-05-06T15:26:21 Z tieunhi Uzastopni (COCI15_uzastopni) C++14
160 / 160
103 ms 24816 KB
#include <bits/stdc++.h>
#define pii pair<int, int>
#define mp make_pair
#define F first
#define S second
#define N 10005
#define PB push_back

using namespace std;

int n, a[N];
vector<pii> dp[N];
vector<int> g[N], v[101];
bitset<101> dd[N][101];

void DFS(int u, int p)
{
	for (auto ve : g[u])
	{
		if (ve == p) continue;
		DFS(ve, u);
	}
	for (int i = 1; i <= 100; i++)
		v[i].clear();
	for (auto ve : g[u])
		for (auto z : dp[ve])
			v[z.F].PB(z.S);

	for (int L = 100; L >= 1; L--)
	{
		if (L == a[u])
		{
			dd[u][L] |= dd[u][L+1];
			dd[u][L].set(L);
		}
		else
		{
			for (auto R : v[L])
				if (R < a[u] || L > a[u])
				{
					dd[u][L] |= dd[u][R+1];
					dd[u][L].set(R);
				}
		}
		for (int R = 100; R >= L; R--)
			if (dd[u][L].test(R) && L <= a[u] && R >= a[u])
				dp[u].PB({L, R});
	}
}
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//freopen("INP.TXT", "r", stdin);
	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;
		g[u].PB(v);
		g[v].PB(u);
	}
	DFS(1, -1);
	cout <<dp[1].size();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1136 KB Output is correct
3 Correct 3 ms 1136 KB Output is correct
4 Correct 3 ms 1208 KB Output is correct
5 Correct 3 ms 1244 KB Output is correct
6 Correct 3 ms 1248 KB Output is correct
7 Correct 3 ms 1304 KB Output is correct
8 Correct 3 ms 1360 KB Output is correct
9 Correct 3 ms 1368 KB Output is correct
10 Correct 3 ms 1372 KB Output is correct
11 Correct 88 ms 17892 KB Output is correct
12 Correct 89 ms 17892 KB Output is correct
13 Correct 89 ms 18012 KB Output is correct
14 Correct 103 ms 24516 KB Output is correct
15 Correct 103 ms 24668 KB Output is correct
16 Correct 103 ms 24816 KB Output is correct
17 Correct 90 ms 24816 KB Output is correct
18 Correct 90 ms 24816 KB Output is correct
19 Correct 88 ms 24816 KB Output is correct
20 Correct 88 ms 24816 KB Output is correct