1 条题解
-
0
#include<iostream> #include<vector> #include<set> using namespace std; int n, l[500001], r[500001], f[500001], c = 0; vector<int>w[500001]; set<int>s; void dfs(int u, int p = -1) { l[u] = ++c; for (int i : w[u]) if (i != p)f[i] = u, dfs(i, u); r[u] = c; if (l[u] == r[u])s.insert(l[u]); } bool empty(int v) { auto it = s.lower_bound(l[v]); return it != s.end() && *it <= r[v]; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; while (--n) { int x, y; cin >> x >> y; w[x].push_back(y); w[y].push_back(x); s.insert(n + 1); } dfs(1); cin >> n; while (n--) { int op, v; cin >> op >> v; if (op == 1) { if (f[v] && empty(f[v]))s.insert(l[f[v]]); s.erase(s.lower_bound(l[v]), s.upper_bound(r[v])); } else if (op == 2)s.insert(l[v]); else cout << !empty(v) << "\n"; } return 0; }
- 1
信息
- ID
- 6868
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 1
- 已通过
- 1
- 上传者