Language: C++

#include<bits/stdc++.h>
 
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long , long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;
 
vector<ll> ans; int visited[5003];
 
void dfs(int node, int p, ll arr[], vector<int> v[]){
      if(visited[node]) return;
      visited[node] = 1;
      for(auto to: v[node]){
            if(to == p){
                  continue;
            }
            ans.pb(to);
            dfs(to, node, arr, v);
      }
      return;
}
 
int run_test(){
      int n, k;
      cin >> n >> k;
      vector<int> v[n + 1];
      for(int i=1; i<=n; i++){
            int p;
            cin >>  p;
            v[p].pb(i);
      }
      ll arr[n + 1];
      for(int i=1; i<=n; i++){
            cin >> arr[i];
      }
      ll out = -100;
      fill(visited, 0);
      for(int i=1; i<=n; i++){
            if(!visited[i]){
                  ans.pb(i);
                  dfs(i, i, arr, v);
                  int t = k % (ans.size());
                  ll sum = 0, alsum = -100;
                  cout << "\n";
                  for(int i=0; i<ans.size(); i++){
                        sum += arr[ans[i]]; ll f = 0;
                        for(int j = 0; j < t; j++){
                              f += arr[ans[j]];
                        }
                        alsum = max(f, alsum);
                  }
                  out = max(out, alsum + sum*(k / ans.size()));
            }
            ans.clear();
      }
      cout << out <<"\n";
      return 0;
}
 
int main(){
    FAST;
    ll t;
    t = 1;
 
    while(t--){
        run_test();
    }
}

Compiler output:
a.cc: In function 'int run_test()':
a.cc:62:28: error: no matching function for call to 'max(long long int&, long long unsigned int)'
   62 |                   out = max(out, alsum + sum*(k / ans.size()));
      |                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:62:28: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   62 |                   out = max(out, alsum + sum*(k / ans.size()));
      |                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303: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:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:62:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   62 |                   out = max(out, alsum + sum*(k / ans.size()));
      |                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~