提交时间:2024-02-29 15:38:31
运行 ID: 26991
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 1e3 + 9, M = 59; vector<int> G[N]; int n, m; LL L, R, a[N]; namespace sub1 { bool dp[2][M][M][209]; void dfs(int u, int fa) { dp[0][u][0][a[u]] = 1; int fl = 0; for (int v : G[u]) { if (v == fa) continue; dfs(v, u), fl ^= 1; for (int i = 0; i <= m; i++) { for (int j = 0; j <= R; j++) dp[fl][u][i][j] = 0; } for (int i = 0; i <= m; i++) { for (int j = 0; j <= R; j++) { if (!dp[fl ^ 1][u][i][j]) continue; for (int x = 0; x <= m - i; x++) { for (int y = 0; y <= R - j; y++) { dp[fl][u][i + x][j + y] |= dp[0][v][x][y]; } } for (int x = 0; x < m - i; x++) { for (int y = L; y <= R; y++) { dp[fl][u][i + x + 1][j] |= dp[0][v][x][y]; } } } } } if (fl) { for (int i = 0; i <= m; i++) { for (int j = 0; j <= R; j++) dp[0][u][i][j] = dp[1][u][i][j]; } } } void Main() { dfs(1, 0); for (int i = 0; i <= m; i++) { int res = 0; for (int j = L; j <= R; j++) res |= dp[0][1][i][j]; putchar(res + '0'); } putchar('\n'); } } signed main() { scanf("%d%d%lld%lld", &n, &m, &L, &R); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); assert(a[i] > 0 && a[i] <= 1e18); } for (int i = 1; i < n; i++) { int u, v; scanf("%d%d", &u, &v); G[u].push_back(v); G[v].push_back(u); } sub1::Main(); return 0; }