Submission #867643

#TimeUsernameProblemLanguageResultExecution timeMemory
867643CookieCat in a tree (BOI17_catinatree)C++14
0 / 100
2 ms8536 KiB
#include<bits/stdc++.h> #include<fstream> using namespace std; ifstream fin("paint.inp"); ofstream fout("paint.out"); #define sz(a) (int)a.size() #define ll long long #define pb push_back #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define ld long double #define vt vector #include<fstream> #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> const ld PI = 3.14159265359; using u128 = __uint128_t; const int x[4] = {1, -1, 0, 0}; const int y[4] = {0, 0, 1, -1}; const ll mod = 1e9 + 7, inf = 1e9; const int mxn = 3e5 + 5; int n, d; pll dp[mxn + 1]; vt<int>adj[mxn + 1]; int dep[mxn + 1]; void dfs(int s, int pre){ vt<pll>comp; for(auto i: adj[s]){ if(i != pre){ dep[i] = dep[s] + 1; dfs(i, s); comp.pb(dp[i]); } } // dp[i] = [max depth, max taken] sort(comp.rbegin(), comp.rend()); ll mndep = inf; for(auto [de, tak]: comp){ if(de + mndep - 2 * dep[s] >= d){ dp[s].second += tak; mndep = min(mndep, de); }else{ dp[s].second += tak - 1; } } if(mndep - dep[s] >= d){ dp[s].second++; mndep = dep[s]; } dp[s].first = mndep; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> d; for(int i = 1; i < n; i++){ int u, v; cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } dfs(1, -1); cout << dp[1].second; return(0); }

Compilation message (stderr)

catinatree.cpp: In function 'void dfs(int, int)':
catinatree.cpp:40:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   40 |     for(auto [de, tak]: comp){
      |              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...