제출 #360210

#제출 시각아이디문제언어결과실행 시간메모리
360210iamsleepyCat in a tree (BOI17_catinatree)C++14
100 / 100
147 ms20704 KiB
#include<bits/stdc++.h> #define ll long long #define pii pair<int,int> using namespace std; const int mxn=2e5+5; const int inf=1e9; int d; int level[mxn]; set<pii> st; vector<int> adj[mxn]; int par[mxn]; int near[mxn]; bool check(int cur,int dist) { if(dist >= d) return true; if(dist + near[cur] < d) return false; if(par[cur] == cur) return true; return check(par[cur],dist + 1); } void update(int cur,int dist) { if(dist >= d) return; near[cur] = min(near[cur],dist); update(par[cur],dist + 1); } void DFS(int cur,int prev) { level[cur] = level[prev] + 1; par[cur] = prev; for(int u : adj[cur]) { if(u != prev) DFS(u,cur); } } int main() { int n; cin>>n; cin>>d; for(int i = 1; i < n; i++) { int u; scanf("%d",&u); adj[u].push_back(i); adj[i].push_back(u); } for(int i = 0; i <= n; i++) near[i] = inf; level[0] = 0; DFS(0,0); vector<pii> v; for(int i = 0; i < n; i++) v.push_back({level[i],i}); sort(v.begin(),v.end()); int res = 0; for(int i = v.size() - 1; i >= 0; i--) { int u = v[i].second; bool f = check(u,0); if(f) { res++; update(u,0); } } cout<<res<<endl; }

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

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