이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
#define int long long
using namespace std;
const int mod=1e9+7,mxn=2e5+5,lg=30,inf=1e18,minf=-1e18;
int n,m,d;
int sz[mxn+10],h[mxn+10];
vector<int>adj[mxn+10];
multiset<int>v[mxn+10];
void dfs(int cur){
sz[cur]=1;
for(auto i:adj[cur]){
h[i]=h[cur]+1;
dfs(i);
sz[cur]+=sz[i];
}
}
void solve(int cur){
int hvy=-1;
for(auto i:adj[cur])if(hvy==-1||sz[i]>sz[hvy])hvy=i;
for(auto i:adj[cur])solve(i);
if(hvy!=-1)swap(v[cur],v[hvy]);
for(auto i:adj[cur]){
if(i==hvy)continue;
while(!v[cur].empty()&&!v[i].empty()&&(*v[cur].begin())+(*v[i].begin())-2*h[cur]<d){
if((*v[i].begin())>(*v[cur].begin()))v[cur].erase(v[cur].begin());
else v[i].erase(v[i].begin());
}
for(auto k:v[i])v[cur].insert(k);
}
if(v[cur].empty()||(*v[cur].begin())-h[cur]>=d)v[cur].insert(h[cur]);
}
int32_t main(){
fastio
cin>>n>>d;
for(int i=1;i<n;i++){
int a;cin>>a;
adj[a].pb(i);
}
dfs(0);
solve(0);
cout<<v[0].size();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
catinatree.cpp:31:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
31 | #pragma GCC optimize ("03,unroll-lopps")
| ^
catinatree.cpp:39:17: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
39 | void dfs(int cur){
| ^
catinatree.cpp:47:19: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
47 | void solve(int cur){
| ^
catinatree.cpp:62:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
62 | int32_t main(){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |