제출 #921338

#제출 시각아이디문제언어결과실행 시간메모리
921338penguin133Cat in a tree (BOI17_catinatree)C++17
100 / 100
72 ms27700 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pi pair<int, int> #define pii pair<int, pi> #define fi first #define se second #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); int n, d; vector <int> adj[200005]; pi mem[200005]; pi dp(int x, int par){ vector <int> tmp; int cur = 0; for(auto i : adj[x]){ if(i == par)continue; pi lmao = dp(i, x); tmp.push_back(lmao.se); cur += lmao.fi; } int in = 0; sort(tmp.begin(), tmp.end()); while((int)tmp.size() > in + 1 && tmp[in] + tmp[in + 1] + 2 < d)in++, cur--; int left = (in < (int)tmp.size() ? tmp[in] + 1 : d); if(left >= d)left -= d, cur++; //cout << x << ' ' << cur << ' ' << left << '\n'; return mem[x] = {cur, left}; } void solve(){ cin >> n >> d; for(int i = 1; i < n; i++){ int a; cin >> a; a++; adj[a].push_back(i + 1); adj[i + 1].push_back(a); } cout << dp(1, -1).fi << '\n'; } main(){ ios::sync_with_stdio(0);cin.tie(0); int tc = 1; //cin >> tc; for(int tc1=1;tc1<=tc;tc1++){ // cout << "Case #" << tc1 << ": "; solve(); } }

컴파일 시 표준 에러 (stderr) 메시지

catinatree.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   46 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...