Submission #1193391

#TimeUsernameProblemLanguageResultExecution timeMemory
1193391akuygaCat in a tree (BOI17_catinatree)C++20
0 / 100
2 ms5440 KiB
#include "bits/stdc++.h" using namespace std; #define ii pair<int,int> #define f first #define s second #define mp make_pair #define ll long long vector<ii> B[100001]; vector<int> A[100001]; vector<bool> vis(100001); vector<int> dist(100001,0); int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); //they said that connected node will be always less than the node //so we can give the less one to always be parent int N,K; cin>>N>>K; vector<int> A[N]; for(int i=1;i<N;i++){ int x; cin>>x; A[x].push_back(i); } int c=1; vector<int> dp(N,0); for(int i=N-1;i>=0;i--){ for(auto n:A[i])dp[i]=max(dp[i],dp[n]); dp[i]++; if(dp[i]>=K){dp[i]%=K; c++;} } cout<<c; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...