#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> bool maximize(T &a, const T &b){ return (a < b ? a = b, 1 : 0); }
template<class T> bool minimize(T &a, const T &b){ return (a > b ? a = b, 1 : 0); }
#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define all(x) x.begin(), x.end()
#define TASK "nonsense"
/// end of template ///
const int N = 1e5 + 15;
int n,a[N];
ll k;
namespace sub1
{
    bool check()
    {
        return n<=100;
    }
    const int N = 102;
    int cnt[N],b[N],ptr,trace[N];
    void work()
    {
        int cur=1;
        b[ptr=1]=cur;
        trace[cur]=1;
        memset(trace,0,sizeof(trace));
        for (int tri=1; tri<=k; ++tri)
        {
            int gogo=a[cur];
            int lst=trace[gogo];
            if (lst==0)
            {
                b[++ptr]=gogo;
                cur=gogo;
            }
            else
            {
                ll need=k-tri;
                int sz=ptr-lst+1;
                need%=sz;
                ptr=lst+need;
                break;
            }
        }
        ++cnt[b[ptr]];
    }
    void solve()
    {
        for (int i=1; i<=n; ++i) for (int j=1; j<=n; ++j)
        {
            int old=a[i];
            a[i]=j;
            work();
            a[i]=old;
        }
        for (int i=1; i<=n; ++i) cout<<cnt[i]<<'\n';
    }
}
void solve()
{
    cin>>n>>k;
    for (int i=1; i<=n; ++i) cin>>a[i];
    if (sub1::check()) return void(sub1::solve());
}
int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    freopen(TASK".inp","r",stdin);
//    freopen(TASK".out","w",stdout);
    int testcase=1;
//    cin>>testcase;
    while (testcase--)
        solve();
//    #define TIME  (1.0 * clock() / CLOCKS_PER_SEC)
//    cerr << "Time elapsed: " << TIME << " s.\n";
    return 0;
}
| # | 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... |