Submission #700074

#TimeUsernameProblemLanguageResultExecution timeMemory
700074tamthegodCat in a tree (BOI17_catinatree)C++17
0 / 100
19 ms23816 KiB
// Make the best become better // No room for laziness #include<bits/stdc++.h> #define int long long #define pb push_back #define fi first #define se second using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxN = 1e6 + 5; const int mod = 1e9 + 7; const ll oo = 1e18; int n, d; vector<int> adj[maxN]; int mark[maxN]; int f[maxN]; int depth[maxN]; struct cmp { bool operator ()(int i, int j) const { return (depth[i] > depth[j] || depth[i] == depth[j] && i < j); } }; set<int, cmp> S; void ReadInput() { cin >> n >> d; for(int i=2; i<=n; i++) { int p; cin >> p; p++; adj[p].pb(i); adj[i].pb(p); } } void dfs(int u, int par) { for(int v : adj[u]) { if(v == par) continue; depth[v] = depth[u] + 1; dfs(v, u); } } void del(int u, int par, int cnt) { mark[u] = 1; S.erase(u); if(cnt == d - 1) return; for(int v : adj[u]) { if(mark[v]) continue; del(v, u, cnt + 1); } } void Solve() { dfs(1, 0); for(int i=1; i<=n; i++) S.insert(i); int res = 0; while(!S.empty()) { res++; del(*S.begin(), 0, 0); } cout << res; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); ReadInput(); Solve(); }

Compilation message (stderr)

catinatree.cpp: In member function 'bool cmp::operator()(long long int, long long int) const':
catinatree.cpp:26:61: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   26 |         return (depth[i] > depth[j] || depth[i] == depth[j] && i < j);
      |                                        ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...