#include using namespace std; const long long INF = 1e18; int main(){ int n; cin >> n; long long k; cin >> k; vector r(n); vector x(n); for (int i=0; i> r[i] >> x[i]; } vector ikeru(n+1, vector(0)); for (int i=0; i weight(n+1); auto dfs = [&](auto self, int i, int p) -> void { if (i < n) weight[i] += x[i]; for (int j: ikeru[i]){ if (j == p) continue; weight[j] += weight[i]; self(self, j, i); } }; dfs(dfs, n, -1); vector shoki(n+1); int shoki_blacklist_num = 0; set blacklist; for (int i=0; i> jisu(n+1); vector iroironahito(n+1, vector>(3)); vector ans(n); vector blacklist_kaihi_nums(n, 0); auto add = [&](int i, int x, int c){ int tar = jisu[i][x]; assert(-1 <= tar && tar <= 1); assert(-1 <= c && c <= 1); assert(-1 <= tar + c && tar + c <= 1); if (tar != 0){ if (blacklist.find(x) != blacklist.end()){ blacklist_kaihi_nums[i] -= 1; } iroironahito[i][tar + 1].erase( iroironahito[i][tar + 1].find(shoki[x]) ); } jisu[i][x] += c; tar += c; if (tar != 0){ if (blacklist.find(x) != blacklist.end()){ blacklist_kaihi_nums[i] += 1; } iroironahito[i][tar + 1].insert( shoki[x] ); } }; auto dfs2 = [&](auto self, int i, int p) -> void { for (int j: ikeru[i]){ if (j == p) continue; self(self, j, i); if ((int)jisu[j].size() > jisu[i].size()){ swap(jisu[j], jisu[i]); swap(blacklist_kaihi_nums[j], blacklist_kaihi_nums[i]); swap(iroironahito[j][0], iroironahito[i][0]); swap(iroironahito[j][2], iroironahito[i][2]); } for (auto [x, c]: jisu[j]){ add(i, x, c); } jisu[j].clear(); } add(i, i, 1); if (i > 0) add(i, i-1, -1); if (i == n) return; if (blacklist_kaihi_nums[i] < shoki_blacklist_num){ return; } long long M_lb = 0; long long M_ub = INF; if (!iroironahito[i][2].empty()){ auto itr = iroironahito[i][2].begin(); long long lb = - x[i] + *itr; itr = iroironahito[i][2].end(); itr--; long long ub = - x[i] + *itr; // 0 <= shoki[k] - x[i] + M <= K narubesi // - shoki[k] + x[i] <= M <= K - shoki[k] + x[i] M_lb = max(M_lb, - ub); M_ub = min(M_ub, - lb + k); } if (!iroironahito[i][0].empty()){ auto itr = iroironahito[i][0].begin(); long long lb = x[i] + *itr; itr = iroironahito[i][0].end(); itr--; long long ub = x[i] + *itr; // 0 <= shoki[k] + x[i] - M <= K narubesi // shoki[k] + x[i] - K <= M <= shoki[k] + x[i] M_lb = max(M_lb, lb - k); M_ub = min(M_ub, ub); } if (M_lb <= M_ub){ ans[i] = 1; } }; dfs2(dfs2, n, -1); for (int i=0; i