删除树节点
#pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #include<string.h> #include<stdlib.h> #include<vector> #include<algorithm> #include<iostream> #include<map> #include<queue> #include<stack> #include<string> #include<functional> #include<math.h> //#include<bits/stdc++.h> using namespace std; typedef long long lint; typedef vector<int> VI; typedef pair<int, int> PII; typedef queue<int> QI; void makedata() { freopen("input.txt", "w", stdout); fclose(stdout); } int w[110000], fa[110000], n, k; VI G[110000]; void dfs(int x, int f) { fa[x] = f; if(w[x] < k) { fa[x] = -1; for(int i = 0; i < G[x].size(); i++) { int y = G[x][i]; dfs(y, f); } } else { for(int i = 0; i < G[x].size(); i++) { int y = G[x][i]; dfs(y, x); } } } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif //makedata(); std::ios::sync_with_stdio(0), cin.tie(0); int root; cin >> n >> k; for(int i = 1; i <= n; i++) cin >> w[i]; for(int i = 1; i <= n; i++) { cin >> fa[i]; G[fa[i]].push_back(i); if(fa[i] == 0) root = i; } dfs(root, 0); for(int i = 1; i <= n; i++) cout << fa[i] << ‘ ‘; return 0; }
鱼雷射击
公平分队II
数组区间