#include int ri() { int n; scanf("%d", &n); return n; } /* WA expected */ #define INF 1000000000 struct Payload { bool ok = true; int enabled_id = -1; int id_max = -1; int id_min = INF; Payload operator * (const Payload &rhs) { if (!ok || !rhs.ok) return {false, -1, -1, INF}; if (enabled_id != -1 && rhs.enabled_id != -1) return {false, -1, -1, INF}; int next_enabled = enabled_id != -1 ? enabled_id : rhs.enabled_id; return {true, next_enabled, std::max(id_max, rhs.id_max), std::min(id_min, rhs.id_min)}; } Payload with_par(int i) { Payload res = *this; if (i > res.id_min) res.enabled_id = res.id_min; return res; } void clean(int i, int par) { if (par == -1) par = INF; if (enabled_id != -1 && enabled_id != id_max && (enabled_id != id_min)) ok = false; id_max = id_min = i; if (enabled_id != -1) enabled_id = i; } }; std::vector > hen; std::vector subtree; void dfs0(int i, int prev) { if (prev != -1) hen[i].erase(std::find(hen[i].begin(), hen[i].end(), prev)); for (auto j : hen[i]) { dfs0(j, i); subtree[i] = subtree[i] * subtree[j]; } bool tmp = prev > subtree[i].id_min; subtree[i].clean(i, prev); if (tmp) subtree[i].enabled_id = i; } std::vector omni; void dfs1(int i, int prev, Payload prev_info) { omni[i] = prev_info; for (auto j : hen[i]) omni[i] = omni[i] * subtree[j]; omni[i].clean(i, -1); std::vector left(hen[i].size()), right(hen[i].size()); for (int j = 1; j < (int) hen[i].size(); j++) left[j] = left[j - 1] * subtree[hen[i][j - 1]]; for (int j = (int) hen[i].size() - 1; j > 0; j--) right[j - 1] = right[j] * subtree[hen[i][j]]; for (int j = 0; j < (int) hen[i].size(); j++) { auto next = left[j] * right[j] * prev_info; bool tmp = hen[i][j] > next.id_min; next.clean(i, hen[i][j]); if (tmp) next.enabled_id = i; dfs1(hen[i][j], i, next); } } int main() { int n = ri(); hen.resize(n); for (int i = 1; i < n; i++) { int a = ri() - 1; int b = ri() - 1; hen[a].push_back(b); hen[b].push_back(a); } subtree.resize(n); dfs0(0, -1); omni.resize(n); dfs1(0, -1, Payload()); /* for (int i = 0; i < n; i++) { fprintf(stderr, "subtree #%d ok:%d [%d, %d] enabled:%d\n", i, subtree[i].ok, subtree[i].id_min, subtree[i].id_max, subtree[i].enabled_id); } for (int i = 0; i < n; i++) { fprintf(stderr, "omni #%d ok:%d [%d, %d] enabled:%d\n", i, omni[i].ok, omni[i].id_min, omni[i].id_max, omni[i].enabled_id); }*/ for (int i = 0; i < n; i++) puts(omni[i].ok ? "Yes" : "No"); return 0; }