제출 #172694

#제출 시각아이디문제언어결과실행 시간메모리
172694rzbtCat in a tree (BOI17_catinatree)C++14
100 / 100
116 ms15712 KiB
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define F first #define S second #define all(x) x.begin(),x.end() #define MAXN 200005 typedef long long ll; using namespace std; int dp[MAXN],udalj[MAXN]; int n,k; vector<int> graf[MAXN]; void dfs(int t){ if(graf[t].empty()){ dp[t]=1; udalj[t]=0; return; } dfs(graf[t][0]); udalj[t]=udalj[graf[t][0]]+1; dp[t]=dp[graf[t][0]]; if(udalj[t]==k){ udalj[t]=0; dp[t]++; } bool prvi=true; for(auto x:graf[t]){ if(prvi){ prvi=false; continue; } dfs(x); if(udalj[t]+udalj[x]+1>=k){ dp[t]+=dp[x]; udalj[t]=min(udalj[t],udalj[x]+1); }else{ dp[t]+=dp[x]-1; udalj[t]=max(udalj[t],udalj[x]+1); } } //printf("%d %d %d",t,udalj[t],dp[t]); } int main() { scanf("%d %d", &n, &k); for(int i=1;i<n;i++){ int t; scanf("%d", &t); graf[t].pb(i); } dfs(0); printf("%d",dp[0]); return 0; }

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

catinatree.cpp: In function 'int main()':
catinatree.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~~
catinatree.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &t);
         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...