QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#737887 | #4357. School Road | caiwen | 0 | 0ms | 0kb | C++14 | 1009b | 2024-11-12 17:03:57 | 2024-11-12 17:03:58 |
answer
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define ls(k) (k)<<1
#define rs(k) (k)<<1|1
#define debug(x) cout<<#x<<"="<<x<<endl
using namespace std;
const int inf=0x3f3f3f3f3f3f3f3f;
const int mod=0;
typedef pair<int,int> pii;
vector<int> ve[100005];
int k,ans,dep[100005];
void dfs(int x,int fa){
int maxx=0;
for(auto to:ve[x]){
dfs(to,x);
maxx=max(maxx,dep[to]);
}
if(x==1) return;
if(maxx+1==k){
if(fa!=1) ans++;
dep[x]=0;
}
else dep[x]=maxx+1;
}
inline void subtask(){
int n;cin>>n>>k;
for(int i=1;i<=n;i++){
int x;cin>>x;
if(i==1){
if(x!=1) ans++;
continue;
}
ve[x].push_back(i);
}
dfs(1,0);
cout<<ans;
}
signed main(){
//freopen("gate.in","r",stdin);
//freopen("gate.out","w",stdout);
ios::sync_with_stdio(false);
int t=1;//cin>>t;
while(t--) subtask();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
14 40 8 12 570429827 6 10 592780730 13 14 299807355 4 10 729771483 4 10 729771483 6 9 746405411 2 3 696576351 12 14 192640790 4 13 284900209 1 2 857968292 12 14 192640790 8 12 570429827 6 10 592780730 6 9 746405411 9 11 329648726 4 13 284900209 2 3 696576351 4 10 729771483 5 11 101819611 3 7 1824073...
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #11:
score: 0
Runtime Error
input:
18 40 3 10 26965732 5 15 67047331 3 17 42474964 13 15 129212204 9 18 142540287 2 14 27157962 5 15 67047331 5 15 67047331 5 15 67047331 4 16 212978971 6 12 51548223 4 18 192438222 13 16 60052417 16 17 162364835 6 17 55527270 9 11 58810843 3 7 95393586 13 15 129212204 2 17 67824762 5 15 67047331 15 16...
output:
result:
Subtask #3:
score: 0
Runtime Error
Test #18:
score: 0
Runtime Error
input:
100000 99999 42115 93495 19881095 21969 68351 161710 7405 86343 27129 37307 45676 320013 30388 71545 117761 22026 68957 65332 77949 81644 2281387 24865 95079 341488 9849 98496 2548159 53911 79572 4962105 24880 62622 1678564 15943 22168 1524688 67424 78323 2450655 32175 74893 1908332 35640 39305 1043...
output:
result:
Subtask #4:
score: 0
Runtime Error
Test #57:
score: 0
Runtime Error
input:
18 400 11 18 145314505 1 18 242896789 1 18 242896789 5 13 31030812 13 18 93451080 1 18 242896789 1 7 123378068 1 18 242896789 1 18 242896789 1 18 242896789 1 18 242896789 1 18 242896789 1 18 242896789 1 3 42183985 1 18 242896789 13 18 93451080 1 18 242896789 13 18 93451080 1 18 242896789 1 18 242896...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #1:
0%