제출 #851063

#제출 시각아이디문제언어결과실행 시간메모리
851063theflessCat in a tree (BOI17_catinatree)C++14
11 / 100
1022 ms9436 KiB
#include <bits/stdc++.h> #define ll long long #define task "name" #define pii pair<ll , int> #define se second #define fi first #define pb push_back #define BIT(s , i) (((s) >> (i)) & 1) #define MASK(i) (1LL << (i)) using namespace std; const int N = 2e3 + 5; const int MOD = 1e9 + 7; const ll loo = 1e18; template<typename T1 , typename T2> bool maximize(T1 &a , T2 b){if(a < b){a = b; return 1;}return 0;} template<typename T1 , typename T2> bool minimize(T1 &a , T2 b){if(a > b){a = b; return 1;}return 0;} int n; int d; vector<int> adj[N]; struct SUB2{ int dp[1501][1501]; int cnt[1501]; void combine(int u , int v){ for(int i = 0 ; i <= n ; i++) cnt[i] = 0; for(int i = 0 ; i <= n ; i++){ for(int j = 0 ; j < n ; j++){ if(i + j + 1 < d) maximize(cnt[min(i , j + 1)] , max(dp[u][i] , dp[v][j])); else maximize(cnt[min(i , j + 1)] , dp[u][i] + dp[v][j]); } } for(int i = 0 ; i <= n ; i++) dp[u][i] = cnt[i]; } void dfs(int u , int par){ dp[u][0] = 1; for(auto v : adj[u]){ if(v == par) continue; dfs(v , u); combine(u , v); } } }f; void sub2(){ f.dfs(0 , -1); cout << *max_element(f.dp[0] , f.dp[0] + n + 1); } void solve(){ cin >> n >> d; for(int i = 1 ; i < n ; i++){ int u; cin >> u; adj[u].pb(i); adj[i].pb(u); } if(d >= n) return void(cout << 1); sub2(); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(task".inp" , "r")){ freopen(task".inp" , "r" , stdin); freopen(task".out" , "w" , stdout); } solve(); }

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

catinatree.cpp: In function 'int main()':
catinatree.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(task".inp" , "r" , stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
catinatree.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen(task".out" , "w" , stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...