Language: C++

/*
    ~A_Pessimist~:)
*/

#include<bits/stdc++.h>
#define ll long long int
using namespace std;

const int sz=50000;
ll ans=-5e18;
vector<ll>vec;
ll p[sz],c[sz];
bool vis[sz];

void dfs(ll node, ll presum)
{
    if(vis[node]) return;

    vis[node]=true;

    presum+=c[node];

    vec.push_back(presum);

    dfs(p[node], presum);
}

void solve()
{
    ll n,k,i,j,rem,temp,mx=0,cycle;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>p[i];
        p[i]--;
    }
    for(i=0;i<n;i++)
    {
        cin>>c[i];
    }
    for(i=0;i<n;i++)
    {
        memset(vis, false, sizeof vis);
        dfs(p[i],0);
        mx=-5e18;

        if(k>=vec.size() && vec.size() && vec.back()>0)
        {
            cycle=k/vec.size();
            rem=k%vec.size();

            temp=(cycle-1LL)*vec.back();

            for(j=0;j<vec.size();j++)
            {
                mx=max(mx, vec[j]);
            }
            ans=max(ans, temp+mx);

            mx=-5e18;

            for(j=0;j<rem;j++)
            {
                mx=max(mx, vec[j]);
            }

            temp=cycle*vec.back();

            ans=max(ans, temp+mx);
        }
        else
        {
            for(j=0;j<min(vec.size(),k);j++)
            {
                ans=max(ans, vec[j]);
            }
        }
        vec.clear();
        temp=0;
    }
    cout<<ans<<endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t=1;
   // cin>>t;

    while(t--)
    {
        solve();
    }
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:73:26: error: no matching function for call to 'min(std::vector<long long int>::size_type, long long int&)'
   73 |             for(j=0;j<min(vec.size(),k);j++)
      |                       ~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:73:26: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'long long int')
   73 |             for(j=0;j<min(vec.size(),k);j++)
      |                       ~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:73:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
   73 |             for(j=0;j<min(vec.size(),k);j++)
      |                       ~~~^~~~~~~~~~~~~~