This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N=3000;
int n;
ll k;
vector<int>graph(N+10);
vector<int>pairs(N+10);
int dfs(ll k, pair<int,int>pareja,int pos){
if(k<=0){
return pos;
}
if(pareja.first==pos){
return dfs(k-1,pareja,pareja.second);
}
return dfs(k-1,pareja, graph[pos]);
}
int main(){
cin >> n >> k;
for(int i=1;i<=n;i++){
int a; cin >> a;
graph[i]=a;
}
for(int x=1;x<=n;x++){
for(int y=1;y<=n;y++){
pairs[dfs(k,{x,y},1)]++;
}
}
for(int i=1;i<=n;i++){
cout<<pairs[i]<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |