criyle/codenet-compile-errors huggingface dataset:
Language: Java

import java.util.*;
import java.io.*;
import java.math.*;

class Main
{
    public static void main(String[] args) throws IOException{
        PrintWriter out = new PrintWriter(System.out);

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        int K = Integer.parseInt(st.nextToken());

        int[] P = new int[N];
        int[] C = new int[N];
        st = new StringTokenizer(br.readLine());
        long ans = Long.MIN_VALUE;

        for (int i=0; i<N; i++) {
            P[i] = Integer.parseInt(st.nextToken())-1;
        }
        st = new StringTokenizer(br.readLine());
        for (int i=0; i<N; i++) {
            C[i] = Integer.parseInt(st.nextToken());
            ans = Math.max(curSum, C[i]);

        }


        for (int i=0; i<N; i++) {
            long curSum = 0;
            int k = K;
            int j = P[i];
            while(j!=i) {
                curSum+=C[j];
                j = P[j];
                ans = Math.max(curSum, ans);
                k--;
                if (k==0) {
                    break;
                }
            }
            k--;
            if (k>0 && curSum>0) {
                curSum+=C[i];
                int len = K-k;
                curSum+= curSum*(k/len);
                k=k%len;
                ans = Math.max(curSum, ans);
                j = P[i];
                while(k--!=0){
                    curSum+=C[j];
                    j = P[j];
                    ans = Math.max(curSum, ans);
                }
            }
        }

        out.println(ans);

        out.close();
    }

    

}


Compiler output:
Main.java:27: error: cannot find symbol
            ans = Math.max(curSum, C[i]);
                           ^
  symbol:   variable curSum
  location: class Main
1 error
Language: C++

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define ins insert
#define sz(x) (long long)x.size()
typedef long long ll;
typedef long double ld;
const int N = 1e5 + 5;
const ld pi = 3.141592653;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;
const ll INF = __LONG_LONG_MAX__;

using namespace std;

int dx[9]={1, -1, 0, 0, 1, 1, -1, -1, 0};
int dy[9]={0, 0, 1, -1, 1, -1, 1, -1, 0};

int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int T = 1;
        //cin>>T;
        while(T--)
        {
                ll n, k, i, j, ans=-1*INF;
                cin>>n>>k;
                vector<ll> p(n+1), c(n+1);
                vector<bool> mark(n+1);
                for(i=1; i<n+1; i++) cin>>p[i];
                for(i=1; i<n+1; i++) cin>>c[i];
                for(i=1; i<n+1; i++){
                        for(j=1; j<n+1; j++) mark[j]=false;
                        ll sum = 0, maxsum = -1*INF, moves = k, pos = i, cnt=0;
                        vector<ll> s;
                        while(moves!=0){
                                moves--; cnt++;
                                pos = p[pos];
                                if(mark[pos]==false){
                                        mark[pos]=true;
                                        sum = sum + c[pos];
                                        maxsum = max(maxsum, sum);
                                        s.pb(sum);
                                }
                                else{
                                        moves++; cnt--; break;
                                }
                        }
                        if(moves!=0){
                                ll q = k/cnt, r = k%cnt;
                                ans = max(ans, maxsum);
                                ans = max(ans, sum*q)
                                if(r!=0){
                                        sum = sum*q;
                                        for(j=0; j<r; j++){
                                                sum = sum + r[j];
                                                ans = max(ans, sum);
                                        }
                                }
                        }
                        else ans = max(maxsum, ans);
                }
                cout<<ans;
        }
        return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:56:54: error: expected ';' before 'if'
   56 |                                 ans = max(ans, sum*q)
      |                                                      ^
      |                                                      ;
   57 |                                 if(r!=0){
      |                                 ~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
using ll = long long;

int main() {
    int n, k;
    cin >> n >> k;

    vector<int> p(n);
    vector<int> c(n);
    rep(i,n) {
        int px;
        cin >> px;
        p[i] = px-1;
    }
    rep(i,n) cin >> c[i];

    
    ll ans = LLONG_MIN;
    rep(sp,n) {
        int pos = sp;
        vector<int> v;
        ll tot = 0;
        while (1) {
            int pos = p[pos];
            v.push_back(c[pos]);
            tot += c[pos];
            if (x == sp) break;
        }   

        int l = v.size();
        ll cum = 0;
        rep(i,l) {
            cum += v[i];
            if (i+1 > k) break;
            ll t = cum;
            if (tot > 0) {
                ll e = (k-i-1)/l);
                t += tot*e;
            }
            ans = max(t, ans);
        }
    }

    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:29:17: error: 'x' was not declared in this scope
   29 |             if (x == sp) break;
      |                 ^
a.cc:39:33: error: expected ',' or ';' before ')' token
   39 |                 ll e = (k-i-1)/l);
      |                                 ^
Language: C++

#include<bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
  ll n,k;
  cin>>n>>k;
  ll a[n+1];
  ll c[n+1];
  for(ll i=1;i<=n;i++)
      cin>>a[i];
  for(ll i=1;i<=n;i++)
      cin>>c[i];

  ll ans=-inf;
  for(ll i=1;i<=n;i++)
  {
    vector<ll>v;
    v.push_back(0);
    ll sum=c[i];
    ll j=a[i];
    ll len=1;    
    while(j!=i)
    {
      
      sum+=c[j];
      j=a[j];
      len++; 
    }
    ll mn=0;
    ll cnt=0;
    while(1)
    {
      cnt++;
      if(cnt>k)
        break;
      mn+=c[j];
      j=a[j];
      ll tmp=mn+(max(0ll,sum)*(k-cnt)/len);
      ans=max(ans,tmp);
      if(i==j)
        break;
    }

    
  }
  cout<<ans<<endl;

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:11: error: 'inf' was not declared in this scope; did you mean 'ynf'?
   17 |   ll ans=-inf;
      |           ^~~
      |           ynf
Language: C

#include<stdio.h>

int main(){
	int n,k,i,j;
	scanf("%d %d",&n,&k);
	int p[n+1] = {0} ;
	long long c[n+1] = {0};
	
	for(i = 1;i < n+1;i++)
		scanf("%d",&p[i]);
	for(j = 1;j < n+1;j++)
		scanf("%lld",&c[j]);
		
	//计算第一次 即从1开始走了k步的结果
	long long maxsum = -10000;
	long long sum = 0;
	int pos = 1;
	for(i = 0;i < k;i++){
		sum += c[p[pos]];
		pos = p[pos];
	}
	//printf("%d\n",sum);
	if(sum > maxsum)
		maxsum = sum;
		
	for(i = 2;i <= n;i++){
		pos = i;
		sum = 0;
		
		for(j = 0;j < k;j++){
			sum += c[p[pos]];
			pos = p[pos];
			//printf("%d ",sum);
			if(sum > maxsum)
				maxsum = sum;
		}
		
		//printf("\n");	
	}
	
	printf("%lld \n",maxsum);
	
	
	return 0;
} 

Compiler output:
main.c: In function 'main':
main.c:6:22: error: variable-sized object may not be initialized except with an empty initializer
    6 |         int p[n+1] = {0} ;
      |                      ^
main.c:7:28: error: variable-sized object may not be initialized except with an empty initializer
    7 |         long long c[n+1] = {0};
      |                            ^
Language: C++

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template<typename T>
struct Edge {
    int u, v;
    T cost;
    Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
    bool operator< (const Edge &e) const {return cost < e.cost;}
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans = -LINF;
int z;

int main(void) {
  int N;
  int K;
  cin >> N >> K;
  vector<int> P(N, 0);
  vector<ll> C(N, 0);
  rep(i, 0, N) {
    cin >> P[i];
    P[i]--;
  }
  rep(i, 0, N) cin >> C[i];

  rep(i, 0, N) {
    int size = 0;
    ll sum = 0;
    int pos = i;
    do {
      sum += C[P[pos]];
      pos = P[pos];
      size++;
    } while (pos != i);

    if (sum<=0 || K<=size) {
      
      int p = i;
      ll x = 0;
      rep(j, 0, min(size,K)) {
        x += C[P[p]];
        p = P[p];
        ans = max(ans, x);
      }

    } else {
      int q = K/size, r = K%size+size;
      sum = sum*(q-1);
      if (q!=0) ans = max(ans, sum);
      pos = i;
      rep(j, 0, r) {
        sum += C[P[pos]];
        pos = P[pos];
        ans = max(ans, sum);
      }
    }
  }
    
  
    
  cout << ans << endl;
  return 0;






Compiler output:
a.cc: In function 'int main()':
a.cc:90:12: error: expected '}' at end of input
   90 |   return 0;
      |            ^
a.cc:42:16: note: to match this '{'
   42 | int main(void) {
      |                ^
Language: C++

#include <bits/stdc++.h>
#define drep(i,cc,n) for(int i=(cc);i<=(n);++i)
#define rep(i,n) drep(i,0,(n)-1)
#define drrep(i,cc,n) for(int i=(cc);i>=(n);--i)
#define rrep(i,n) drrep(i,0,(n)-1)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,v.size())if(i==0)cout << v[i];else cout << " " << v[i]; cout << endl;
#define arrprint(v,n) rep(i,n)if(i==0)cout << v[i];else cout << " " << v[i]; cout << endl;
#define matprint(v,n,m) rep(i,n){rep(j,m){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const ll INF=-1001001001001;
using ll = long long;
using P = pair<int,int>;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す


int main(){
    int n,k;
    cin >> n >> k;
    vector<int> p(n),c(n);
    rep(i,n){cin >> p[i];p[i]--;}
    rep(i,n)cin >> c[i];
    vector<int> a[5000];
    set<int> s;
    int con = 0;
    rep(now,n){
        if(s.find(now) != s.end())continue;
        a[con].push_back(now);
        s.insert(now);
        while(p[now] != a[con][0]){
            now = p[now];
            a[con].push_back(now);
            s.insert(now);
        }
        con++;
    }
    ll ans = INF;
    rep(i,con){
        ll tans = 0;
        int l = sz(a[i]);
        ll all = 0;
        rep(j,l) all += c[a[i][j]];
        int kk;
        if(all>0){
            if(k/l > 1){
                tans = all*(k/l-1);
                kk  = k%l+l;
            }else{
                kk = k;
            }
        }else{
            kk = min(k,l);
        }
        ll ttans = INF;
        rep(j1,l){
            ll tans2 = 0;
            rep(jj,kk){
                int j2 = (j1+jj)%l;
                tans2 += c[a[i][j2]];
                ttans = max(ttans,tans2);
                // if(i == 1)cout << jj << " " << tans2 << endl;;
            }
        }
        tans += ttans;
        // cout << i << " " << l << " " << tans << " " << kk << " " << all << endl;
        ans = max(ans,tans);
    }
    // cout << con << endl;

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Compiler output:
a.cc:14:7: error: 'll' does not name a type
   14 | const ll INF=-1001001001001;
      |       ^~
a.cc: In function 'int main()':
a.cc:41:14: error: 'INF' was not declared in this scope
   41 |     ll ans = INF;
      |              ^~~
Language: C++

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define orep(i,n) for(int i = 1; i <= (n); i++)
#define srep(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define ll long long
#define P pair<int,int>
#define vi vector<int>
#define vvi vector<vi>

using namespace std;

void pv(vi v) {
    cout << "[" ;
    for(auto c : v) {
        cout << c << " ";
    }
    cout << "]" << endl;
}

const ll INF = 1000000000000000000;

ll g(int n, vi &v) {
    int length = v.size();
    if(length < n) return -INF;
    ll res = -INF;
    ll tmp=0;
    rep(i,n) tmp += v.at(i);
    res = tmp;
    int i = 0;int j = n % length;
    while(i != length) {
        tmp -= v.at(i);
        tmp += v.at(j);
        res = max(res,tmp);
        i++;
        j++;
        j %= length;
    }
    return res;
}

ll f(vi &v, ll sum,int k) {
    ll res = 0;
    int length = v.size();
    ll tmp = -INF;
    if(sum > 0 && length <= k) {
        res += sum * (k/length);
        orep(i,k%length) {
            tmp = max(tmp,g(i,v));
        }
        res += tmp;
    } else if(sum > 0 && length > k) {
        orep(i,k) {
          tmp += max(tmp,g(i,v));
        }
        res += tmp;
    } else {
      if(k <= length) {
        orep(i,k) {
            tmp = max(tmp,g(i,v));
        }
        res = tmp;
      } else {
        orep(i,length) {
            tmp = max(tmp,g(i,v));
        }
        res = tmp;
      }
    }
    return res;
}

int main() {
    int n,k;cin >> n >> k;
    vi p(n,0);
    rep(i,n) {
        cin >> p.at(i);
        p.at(i)--;
    }
    vi c(n,0);
    rep(i,n) cin >> c.at(i);
    
    vvi loop;
    vector<ll> sm;
    vi check(n,0);
    rep(i,n) {
        if(check.at(i) == 1) continue;
        vi tmp;
        ll tsum = 0;
        int j = i;
        do{
            check.at(j)++;
            tmp.push_back(c.at(j));
            tsum+=c.at(j);
            j = p.at(j);
        }
        while(j != i);
        loop.push_back(tmp);
        sm.push_back(tsum);
    }
    ll ans = -INF;
    
    rep(i,loop.size()) {
        ans = max(ans,f(loop.at(i),sm.at(i),k));
    }
    
    if(ans==-INF) exit();
    cout << ans << endl;

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:106:23: error: too few arguments to function 'void exit(int)'
  106 |     if(ans==-INF) exit();
      |                   ~~~~^~
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:42,
                 from a.cc:1:
/usr/include/stdlib.h:756:13: note: declared here
  756 | extern void exit (int __status) __THROW __attribute__ ((__noreturn__));
      |             ^~~~
Language: C++

#include<iostream>
#include<vector>
using namespace std;
vector<long> p;
vector<long> c;

int main(){
    long n,k;
    cin >> n >> k;

    p.resize(n);
    c.resize(n);
    for(int i = 0;i < n;i++){
        cin >> p[i];
        p[i]--;
    }
    for(int i = 0;i < n;i++){
        cin >> c[i];
    }
    long ans = LONG_MIN;

    vector<long> round(n);//何回回れば元の位置に戻るか
    for(int i = 0;i < n;i++){
        long cycle = 0;
        long sum = 0;
        int v = i;
        //i始まりで何回回れば1周できるかと1周回った際の合計
        while(true){
            cycle++;
            sum += c[v];
            v = p[v];
            if(v == i){
                break;
            }
        }
        long path = 0;
        long cnt = 0;

        while(true){
            cnt++;
            path += c[v];

            if(cnt > k)break;
            long num = (k - cnt) / cycle;
            long score = path + max(0l,sum) * cycle;
            ans = max(ans,score);
            v = p[v];
            if(v == i)break;
        }

        
    }
    cout << ans << endl;
    


    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:16: error: 'LONG_MIN' was not declared in this scope
   20 |     long ans = LONG_MIN;
      |                ^~~~~~~~
a.cc:3:1: note: 'LONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    2 | #include<vector>
  +++ |+#include <climits>
    3 | using namespace std;
Language: Java

import java.util.*;

public class emne {
    public static Scanner Scan = new Scanner(System.in);

    public static void main(String[] args) {
        int n = Scan.nextInt();
        int k = Scan.nextInt();

        int p[] = new int[n+1];
        long c[] = new long[n+1];
        for(int i=1; i<=n; i++) p[i] = Scan.nextInt();
        for(int i=1; i<=n; i++) c[i] = Scan.nextLong();

        boolean vis[] = new boolean[n+1];

        long ans = (long)-1e18;
        for(int i=1; i<=n; i++) {
            long now = 0;
            Arrays.fill(vis, false);
            int nxt = p[i];

            int z = k;
            while(z != 0) {
                now += c[nxt];
                vis[nxt] = true;
                nxt = p[nxt]; z--;
                ans = Math.max(ans, now);
            }

        }


        System.out.println(ans);
    }
}

Compiler output:
Main.java:3: error: class emne is public, should be declared in a file named emne.java
public class emne {
       ^
1 error
Language: C++

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void){
    int n;
    ll k;
    cin >> n >> k;
    vector<int> p(n), c(n);
    rep(i, n){
        cin >> p[i];
        --p[i];
    }
    rep(i, n) cin >> c[i];
    ll ans = -1e9 - 1;
    rep(i, n){
        int to = p[i];
        ll sum = 0;
        vector<ll> r;
        while(1){
            sum += c[to];
            r.push_back(c[to]);
            if(to == i || r.size >= k) break;
            to = p[to];
        }
        ll ts = 0, rs = r.size();
        for(ll i = 0; i < rs; ++i){
            ts += r[i];
            ans = max(ans, ts);
            if(sum > 0)
                ans = max(ans, sum * ((k - i - 1) / rs) + ts);
        }
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:29: error: invalid use of member function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = long long int; _Alloc = std::allocator<long long int>; size_type = long unsigned int]' (did you forget the '()' ?)
   25 |             if(to == i || r.size >= k) break;
      |                           ~~^~~~
      |                                 ()
Language: C++

#include <bits/stdc++.h>
using namespace std;
# define ll  long long int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int p[5005];
int c[5005];
vector<ll> prefixSums;
bool vis[5005];

void dfs(int src, ll currSum){
	if(vis[src])
		return;
	vis[src] = true;
	currSum += c[u];
	prefixSums.push_back(currSum);
	dfs(p[u], currSum);
}

int  main()
{
    #ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("output.txt", "w", stdout);
    #endif
     IOS
     int n, k;
     cin >> n >> k;
     for(int i = 0; i < n; i++){
     	cin >> p[i];
     	p[i]--;
     }
     for(int i = 0; i < n; i++)
     	cin >> c[i];
     ll ans = -1e18;
     for(int i = 0; i < n; i++){
     	memset(vis, false, sizeof(vis));
     	dfs(i, 0);
     	if(prefixSums.back() > 0 && k > (int)prefixSums.size()){
     		ll cycles = (ll)(k/(int)prefixSums.size());
     		ll left = (ll)(k%(int)prefixSums.size());
     		ll maxi = -1e18;
     		for(int x = 0; x < (int)track.size(); x++)
     			maxi = max(maxi, prefixSums[x]);
     		ans = max(ans, (cycles - 1LL)*(prefixSums.back()) + maxi);
     		maxi = -1e18;
     		for(int x = 0; x < left; x++)
     			maxi = max(maxi, prefixSums[x]);
     		ans = max(ans, (cycles*prefixSums.back()) + maxi);
     	}
     	else{
     		for(int j = 0; j < min((int)prefixSums.size(), k); j++)
     			ans = max(ans, prefixSums[j]);
     	}
     	prefixSums.clear();
     }
     cout << ans;
     return 0;
}

Compiler output:
a.cc: In function 'void dfs(int, long long int)':
a.cc:23:22: error: 'u' was not declared in this scope
   23 |         currSum += c[u];
      |                      ^
a.cc: In function 'int main()':
a.cc:51:41: error: 'track' was not declared in this scope
   51 |                 for(int x = 0; x < (int)track.size(); x++)
      |                                         ^~~~~
Language: C++

#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)

#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

using namespace std;
using ll = long long;
using vel = vector<ll>;
using ves = vector<string>;
using veb = vector<bool>;
using qul = queue<ll>;

void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

int binary_search(ll x, vel a){
    auto ite = lower_bound(ALL(a), x);
    if(ite != a.end() && *ite == x) {
        return ite - a.begin() ;
    } else {
        return -1;
    }

}

ll modpow(ll a, ll n, ll mod) {
    if(n == 0)
        return 1;
    if(n == 1)
        return a % mod;
    if(n % 2 == 1)
        return (a * modpow(a, n - 1, mod)) % mod;
    ll t = modpow(a, n / 2, mod);
    return (t * t) % mod;
}

int main() {
    ll N, K, sum = 0, sum2 = 0, next, count = 0, ans, num, num2,  m_l, m_l2;
    cin >> N >> K;
    vel P(N), C(N), check(N);
    bool minflag= false;
    REP(i, N) cin >> P[i];
    REP(i, N) cin >> C[i];
    
    bool flag = false;
    ans = C[0];
    REP(i,N){
        count = 0;
        next = i;
        sum = 0;
        m_l = C[next];
        REP(j,N){
            sum += C[next];
            next = P[next]-1;
            ans = max(ans, sum);
            m_l2 = max(m_l2, sum2);
            count++;
            if(j+1 >= K || next == i)
                break;
        }

        next = i;
        sum2 = 0;
        REP(j, K%count) {
            sum2 += C[next];
            next = P[next]-1;
            m_l = max(m_l, sum2);
        }



        if(sum >= 0){
            if(K%count==0) m_l = 0;
            num = K/count * sum + m_l;
            num2 = K/count * (sum - 1) + m_l2
            num = max(num, num2)
            ans = max(ans, num);
        } else {
            ans = max(ans, m_l);
        }
    }

    cout << ans << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:78:46: error: expected ';' before 'num'
   78 |             num2 = K/count * (sum - 1) + m_l2
      |                                              ^
      |                                              ;
   79 |             num = max(num, num2)
      |             ~~~
Language: C++

#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iomanip>
typedef long long ll;
using namespace std;

vector<ll> a(5005);
vector<ll> b(5005);
vector<ll> track;
bool vis[5005];

 void dfs(int u , long long total_cycle){
        if(vis[u]) return ;
        vis[u]=true;
        total_cycle+=b[u];
        track.push_back(+0);
        dfs(a[u],total_cycle);
    }


void solve(){
        int n,k;
        cin>>n>>k;
        for(int i=0;i<n;i++){
            cin>>a[i];
            a[i]--;
        }
        for(int i=0;i<n;i++)
            cin>>b[i];
        ll ans=-(1e18);
        for(int i=0;i<n;i++){
            memset(vis,false,sizeof(vis));
            dfs(i,0);
            if(track.back()>0 && k>=(int)(track.size())){
                ll cycles=(ll)(k/(int)track.size());
                ll left=(ll)(k%(int)track.size());
                ll maxi=-1e18;
                for(int x=0;x<(int)track.size();x++)
                    maxi=max(maxi,track[x]);
                ans=max(ans,(cycles-1LL)*(track.back())+maxi);
                maxi=-1e18;
                for(int x=0;x<left;x++)
                    maxi=max(maxi,track[x]);
                ans=max(ans,(cycles*track.back()) + maxi);
            }
            else{
                for(int j=0;j<(min((int)track.size(),k));j++){
                    ans=max(ans,track[j]);
                }
            }
            track.clear();
        }
        cout<<ans;
        return;
    }


int main()
{

	ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
		//freopen("in.txt","r",stdin);
        int t=1;
        // cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
	return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:34:13: error: 'memset' was not declared in this scope
   34 |             memset(vis,false,sizeof(vis));
      |             ^~~~~~
a.cc:6:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    5 | #include <iomanip>
  +++ |+#include <cstring>
    6 | typedef long long ll;
Language: C++

#include <bits/stdc++.h>
using namespace std;
const long long INF=1e18;
int main() {
  int N,K; cin >>N >>k;
  vector <int> P(N),C(N);
  for (int i=0;i<N;i++) cin >>P[i],--P[i];
  for (int i=0;i<N;i++) cin >>C[i];
  
  long long ans=-INF;
  for (int i=0;i<N;i++) {
    int v=i;
    long long cycle_sum=0;
    int cycle_cnt=0;
    while (1) {
      cycle_cnt++;
      cycle_sum+=C[v];
      v=P[v];
      if (v==i) break;
    }
    long long path=0;
    int cnt=0;
    
    while (1) {
      cnt++;
      path+=C[v];
      if (cnt>K) break;
    }
  }
  cout <<ans <<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:5:22: error: 'k' was not declared in this scope
    5 |   int N,K; cin >>N >>k;
      |                      ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define itn int
#define tin int
#define tni int
#define veci vector<int>
typedef long long ll;
int main(){
	int n,k;
	cin>>n>>k;
	veci P(n);
	for(int i=0;i<n;i++){
		cin>>P[i];
		P[i]--;
	}
	veci c(n);
	for(int i=0;i<n;i++){
		cin>>c[i];
	}
	if(k<=n){
		ll ans=-1000000000;
		for(int i=0;i<n;i++){
			ll p=1;
			ll s=0;
			for(int j=0;j<k;j++){
				p+=P[p];
				s+=c[p];
				ans=max(ans,s);
			}
		}
		cout<<ans<<endl;
	}else{
		vector<veci >	next(31,veci(n));
		for(int i=0;i<n;i++){
			next[0][i]=p[i];
		}
		for(itn i=1)
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:35:36: error: 'p' was not declared in this scope
   35 |                         next[0][i]=p[i];
      |                                    ^
a.cc:37:28: error: expected ';' before ')' token
   37 |                 for(itn i=1)
      |                            ^
      |                            ;
a.cc:37:28: error: expected primary-expression before ')' token
a.cc:37:28: error: expected ';' before ')' token
   37 |                 for(itn i=1)
      |                            ^
      |                            ;
a.cc:38:9: error: expected primary-expression before '}' token
   38 |         }
      |         ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

long long P[5010];
long long C[5010];

int main() {
  long long N, K;
  cin >> N >> K;
  for (long long i = 1; i <= N; i++) {
        cin >> P[i];
  }
  for (long long i = 1; i <= N; i++) {
        cin >> C[i];
  }
  
  long long nmax = -1000000000;//各Nについてのmax
  long long ntemp = 0;//各Nについての途中得点
  long long allmax = -1000000000;//全部の最大値
  int flag;
  int cnt;

  //全マスについて最大値を計算する
  for (int i = 1; i <= N; i++) {
    nmax = -1000000000;
    ntemp = 0;
    flag = 1;//サイクルを回ったかどうかのフラグ
    cnt = 1;//サイクルの数 最初の１回は動いてからスタート
    int temp = i;//最初のマスを記録
    int now = temp;//現在のマス
    //最初の移動をする
    now = P[now];
    ntemp+= C[now];
    nmax=max(nmax,ntemp);
    allmax=max(nmax.ntemp);
    //スタート
    do {
      now = P[now];
      ntemp += C[now];
      nmax = max(nmax, ntemp);
      allmax = max(allmax, nmax);
      cnt++;
      if (cnt == K) {
        flag = 0;//サイクルを回らずに終わった場合
        //cout<<"サイクルを回らずに終わった場合"<<endl;
        break;
      }
    }
    while (now != temp);
    //cout<<now<<" "<<cnt<<"flag"<<flag<<"ntemp"<<ntemp<<endl;
    
    //サイクルを回らずに終わった場合
    if (flag != 1) {
      allmax = max(allmax, nmax);
      continue;
    }
    
    //サイクルした場合
      //サイクル後スコアが減少している場合
    if (ntemp <= 0) {
      allmax = max(allmax, nmax);
      //cout<<nmax<<"$"<<allmax<<endl;
      continue;
    }
    
    //サイクル後スコアが増加している場合
    if (ntemp > 0) {
      long long sc = K / cnt;//何サイクル回ったか
      //サイクルを回った余りの数　zc
      long long zc = K - sc * cnt;//残り回数を計算
      ntemp=sc*ntemp;
      nmax = max(nmax, ntemp);
      //cout<<"sc"<<sc<<"zc"<<zc<<"ntemp"<<ntemp<<endl;
      for (int j = 0; j < zc; j++) {
        now = P[now];
        ntemp += C[now];
        nmax = max(nmax, ntemp);
      }
      //cout<<nmax<<"*"<<allmax<<endl;
      allmax = max(allmax, nmax);
      continue;
    }
  }
  //cout<<flag<<" "<<cnt<<endl;
  cout << allmax << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:35:21: error: request for member 'ntemp' in 'nmax', which is of non-class type 'long long int'
   35 |     allmax=max(nmax.ntemp);
      |                     ^~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

const long long INF = 1LL<<60;
int N;
long long K;
vector<int> P;
vector<long long> C;

long long solve(s) {
    long long res = -INF;

    // 順列を各サイクルに分解する
    vector<bool> used(N, false);
    vector<vector<long long>> ss;
    for (int i = 0; i < N; ++i) {
        if (used[i]) continue;
        int cur = i;
        vector<long long> s;
        while (!used[cur]) {
            used[cur] = true;
            s.push_back(C[cur]);
            cur = P[cur];
        }
        ss.push_back(s);
    }

    // 各サイクルごとに考える
    for (auto vec : ss) {
        long long M = vec.size();

        // サイクルを二週したものの累積和
        vector<long long> sum(M*2+1, 0);
        for (int i = 0; i < M*2; ++i) sum[i+1] = sum[i] + vec[i%M];

        // amari[r] := 連続する r 個の総和の最大値
        vector<long long> amari(M, -INF);
        for (int i = 0; i < M; ++i) {
            for (int j = 0; j < M; ++j) {
                chmax(amari[j], sum[i+j] - sum[i]);
            }
        }

        // 余りの長さで場合分け
        for (int r = 0; r < M; ++r) {
            if (r > K) continue;
            long long q = (K - r) / M;
            if (r == 0 && q == 0) continue;

            if (sum[M] > 0) chmax(res, amari[r] + sum[M] * q);
            else if (r > 0) chmax(res, amari[r]);
        }
    }
    return res;
}

int main() {
    cin >> N >> K;
    P.resize(N); C.resize(N);
    for (int i = 0; i < N; ++i) cin >> P[i], --P[i];
    for (int i = 0; i < N; ++i) cin >> C[i];
    cout << solve() << endl;
}

Compiler output:
a.cc:24:17: error: 's' was not declared in this scope
   24 | long long solve(s) {
      |                 ^
a.cc: In function 'int main()':
a.cc:76:18: error: 'solve' cannot be used as a function
   76 |     cout << solve() << endl;
      |             ~~~~~^~
Language: C++

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k,ans=-114514114514114514,p[50001],c[50001],nxt[50001][33];
int sum[50001][33];
signed main()
{
	scanf("%lld %lld",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%lld",&p[i]);
	for(int i=1;i<=n;i++)
		scanf("%lld",&c[i]);
	if(k<=n)
	{
		for(int i=1;i<=n;i++)
			int now=i,s=0;
			for(int l=1;l<=k;l++)
			{
				now=p[now],s=0;
				s+=c[now];
				ans=max(ans,s);
			}
		cout<<ans;
		return 0;
	}
	for(int i=1;i<=n;i++)
		sum[i][0]=c[p[i]];
	for(int i=1;i<=n;i++)
		nxt[i][0]=p[i];
	for(int i=1;i<=32;i++)
		for(int l=1;l<=n;l++)
			nxt[l][i]=nxt[nxt[l][i-1]][i-1];
	for(int i=1;i<=32;i++)
		for(int l=1;l<=n;l++)
			sum[l][i]=sum[l][i-1]+sum[nxt[l][i-1]][i-1];
	for(int i=1;i<=n;i++)
	{
		int now=i,s=0,kk=k;
		for(int l=1;l<=n;l++)
		{
			now=p[now];
			s+=c[now];
			ans=max(ans,s); 
		}
		now=i,s=0;
		for(int i=0;i<=32;i++)
			if((k-n)>>j&1)
			{
				s+=sum[now][i];
				now=nxt[now][i];
			}
		for(int l=1;l<=n;l++)
		{
			now=p[now];
			s+=c[now];
			ans=max(ans,s); 
		}
	}
	cout<<ans;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:33: error: 'now' was not declared in this scope; did you mean 'pow'?
   19 |                                 now=p[now],s=0;
      |                                 ^~~
      |                                 pow
a.cc:19:44: error: 's' was not declared in this scope
   19 |                                 now=p[now],s=0;
      |                                            ^
a.cc:47:35: error: 'j' was not declared in this scope
   47 |                         if((k-n)>>j&1)
      |                                   ^
Language: C++

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k,ans=-114514114514114514,p[50001],c[50001],nxt[50001][33];
int sum[50001][33];
int main()
{
	scanf("%lld %lld",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%lld",&p[i]);
	for(int i=1;i<=n;i++)
		scanf("%lld",&c[i]);
	if(k<=n)
	{
		for(int i=1;i<=n;i++)
			int now=i,s=0;
			for(int l=1;l<=k;l++)
			{
				now=p[now],s=0;
				s+=c[now];
				ans=max(ans,s);
			}
		cout<<ans;
		return 0;
	}
	for(int i=1;i<=n;i++)
		sum[i][0]=c[p[i]];
	for(int i=1;i<=n;i++)
		nxt[i][0]=p[i];
	for(int i=1;i<=32;i++)
		for(int l=1;l<=n;l++)
			nxt[l][i]=nxt[nxt[l][i-1]][i-1];
	for(int i=1;i<=32;i++)
		for(int l=1;l<=n;l++)
			sum[l][i]=sum[l][i-1]+sum[nxt[l][i-1]][i-1];
	for(int i=1;i<=n;i++)
	{
		int now=i,s=0,kk=k;
		for(int l=1;l<=n;l++)
		{
			now=p[now];
			s+=c[now];
			ans=max(ans,s); 
		}
		now=i,s=0;
		for(int i=0;i<=32;i++)
			if((k-n)>>j&1)
			{
				s+=sum[now][i];
				now=nxt[now][i];
			}
		for(int l=1;l<=n;l++)
		{
			now=p[now];
			s+=c[now];
			ans=max(ans,s); 
		}
	}
	cout<<ans;
	return 0;
}

Compiler output:
cc1plus: error: '::main' must return 'int'
a.cc: In function 'int main()':
a.cc:19:33: error: 'now' was not declared in this scope; did you mean 'pow'?
   19 |                                 now=p[now],s=0;
      |                                 ^~~
      |                                 pow
a.cc:19:44: error: 's' was not declared in this scope
   19 |                                 now=p[now],s=0;
      |                                            ^
a.cc:47:35: error: 'j' was not declared in this scope
   47 |                         if((k-n)>>j&1)
      |                                   ^
Language: C++

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=5010;
ll dist[N][N],circle[N],mark[N];
bool st[N];
int pos[N],n;
ll k;
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>pos[i];
    for(int i=1;i<=n;i++) cin>>mark[i];
    for(int i=1;i<=n;i++)
    {
        memset(st,0,sizeof st);
        int j=pos[i],idx=0;
        while(!st[j])
        {
            st[j]=1;
            idx++;
            dist[i][idx]=dist[i][idx-1]+mark[j];
            j=pos[j];
        }
        circle[i]=idx;
        
    }
    ll res=-1e18;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=circle[i];j++)
        {
            ll x=dist[i][j];
            if(k<j) break;
            if(dist[i][circle[i]]>=0) x+=(k-j)/circle[i]*dist[i][circle[i]];
            res=max(res,x);
        }
    cout<<res<<endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:20:9: error: 'memset' was not declared in this scope
   20 |         memset(st,0,sizeof st);
      |         ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    4 | #include<algorithm>
  +++ |+#include <cstring>
    5 | using namespace std;
Language: C

#include <bits/stdc++.h>
using namespace std;
int s=-1073741825,h,a[1005],b[1005],m;
void bfs(int i,int k)
{
	if(k>=h)return;
	m+=b[a[i]];
	s=max(s,m);
	//cout<<m<<' ';
	bfs(a[i],k+1);
	return;
}
int main()
{
	int n;
	cin>>n>>h;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		a[i]=x-1;
		a[x]=i-1;
	}
	for(int i=0;i<n;i++)
	{
		m=0;
		cin>>b[i];
	}
	for(int i=0;i<n;i++)
	{
		m=0;
		bfs(i,0);
		//cout<<'\n';
	}
	cout<<s<<'\n';
}


Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;
struct UF
{
  vector<ll> par;
  vector<ll> sz;
  vector<ll> rank;
  UF(ll n):par(n),sz(n),rank(n){
    for(ll i = 0; i < n; i++){
      par[i] = i;sz[i] = 1;rank[i] = 0;
    }
  }
  ll find(ll x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
  }
  void merge(ll x, ll y) {
    x = find(x); y = find(y);
    if (x == y) return;
    if(rank[x] < rank[y]){
      par[x] = y;
      sz[y] += sz[x];
    }
    else{
      par[y] = x;
      sz[x] += sz[y];
      if(rank[x] == rank[y])rank[x]++;
    }
  }
  bool same(ll x, ll y) { return find(x) == find(y); }
  ll size(ll n){return sz[find(n)];}
};
ll main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;cin>>n>>k;
  vi P(n),C(n);
  UF uni(n);
  ll cnt = 0,ans =-llINF;
  for(auto &a:P){cin>>a;uni.merge(cnt++,--a);}
  for(auto &a:C){cin>>a;ans = max(ans,a);}
  map<ll,ll>cost;
  for(ll i=0;i<n;i++){
    cost[uni.find(i)] += C[i];
  }

  for(ll i=0;i<n;i++){
    ll now = i,sum = 0;
    sum += cost[uni.find(i)] * (k/uni.size(i));
    if(sum <= 0){
      sum = 0;
      ll loop = min(k,uni.size(i));
      for(ll j=0;j<loop;j++){
	now = P[now];
	sum += C[now];
	ans = max(ans,sum);
      }
    }else{
      ans = max(ans,sum);
      ll loop = k%uni.size(i);
      for(ll j=0;j<loop;j++){
	now = P[now];
	sum += C[now];
	ans = max(ans,sum);
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int N,K,tmp;
int Arr[5000];
int Vis[5000];
int Cost[5000];


void solve(){

   cin >> N >> K;

   for (int i = 0; i < N; i++)
   {
       cin >> tmp;
        tmp--;
       Arr[i] = tmp;
       Vis[i] = 0;
    }

   for (int i = 0; i < N; i++)
   {
       cin >> tmp;
       Cost[i] = tmp;
   }


    ll ans = -100000000000;

    int cur, curK, circsize;
    ll cmax, val;
    for (int i = 0; i < N; i++)
    {
        cur = i;
        val = Cost[Arr[cur]];
        cur = Arr[i];
        cmax = val;
        curK = K;
        circsize = 0;
        curK--;
        circsize++;

        while(cur != i && curK > 0){
            val += Cost[Arr[cur]];
            cur = Arr[cur];
            cmax = max(cmax,val);
            circsize++;
            curK--;
            
        }

        ans = max(ans, cmax);
        if(val > 0 && curK > 0)
        {
                ll tcmax = (K/circsize -1 ) * val;
                ans = max(ans, tcmax+cmax);
                tcmax += val;
                curK = (K % circsize);
                
                if(K > circ)

                if(curK > 0){
                    cur = i;
                    val = Cost[Arr[cur]];
                    cur = Arr[i];
                    cmax = max(val,(ll)0);
                    circsize = 0;
                    curK--;

                    while(cur != i && curK > 0){
                        val += Cost[Arr[cur]];
                        cur = Arr[cur];
                        cmax = max(cmax,val); 
                        curK--;

                    }
                    tcmax = tcmax+cmax;
                }
                
                ans = max(ans, tcmax);
        }
    }
    cout << ans << endl;
}






int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();

}

Compiler output:
a.cc: In function 'void solve()':
a.cc:64:24: error: 'circ' was not declared in this scope
   64 |                 if(K > circ)
      |                        ^~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, k;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
    }
    vector<ll> c(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    ll ans = -1e18;
    for (int i = 0; i < n; i++) {
        vector<ll> a(1, c[i]);
        int j = i;
        while (p[j] != i) {
            a.emplace_back(c[p[j]]);
            j = p[j];
        }
        ll all = accumulate(a.begin(), a.end(), 0LL);
        all = max(all, 0LL);
        ll sub = 0;
        for (int l = 0; l < a.size(); l++) {
            sub += a[l];
            ans = max(ans, sub + all * ((k - l - 1) / a.size()));
        }
    }
    cout << ans << '\n';
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:37:22: error: no matching function for call to 'max(ll&, long long unsigned int)'
   37 |             ans = max(ans, sub + all * ((k - l - 1) / a.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:37:22: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   37 |             ans = max(ans, sub + all * ((k - l - 1) / a.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:37:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   37 |             ans = max(ans, sub + all * ((k - l - 1) / a.size()));
      |                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

ll max(ll a, ll b){
    return (a>b)?a:b;
}

const ll INF = 1000000000000000;

//集合を表すデータ構造、根は大きさを負で持ち、子は根を正で持つ
//[0]に全体の集合の数を入れる
//swapを使用するため<utility>をインクルードする
struct UnionFind{
    vector<int>data;
    UnionFind(int size) :   data(size+1, -1){
        data[0] = size;
    }

    //集合のmerge
    //すでに同じならfalse
    bool merge(int x, int y){
        x = root(x);    y = root(y);
        if(x == y)  return false;
        //要素数の少ない方を多い方に繋げる
        if(data[y] < data[x])   swap(x, y);
        data[x] += data[y];
        data[y] = x;
        data[0]--;
        return true;
    }

    //どの集合に属しているか
    int root(int x){
        //根に繋ぎ直す
        return (data[x] < 0) ? x : (data[x] = root(data[x]));
    }

    //ある要素が属する集合の大きさ
    int size(int x){
        return -data[root(x)];
    }

    //集合の数
    int set(){
        return data[0];
    }
};

int main(){
    int n;  cin >> n;
    ll k;   cin >> k;
    UnionFind uf(n);
    vector<int>p(n+1);    
    vector<int>g(n+1);
    rep(i, n){
        cin >> p[i+1];
        uf.merge(i+1, p[i+1]);
        g[i+1] = p[i+1];
    }
    vector<ll>c(n+1);     
    rep(i, n)   cin >> c[i+1];
    vector<vector<ll>>score(n+1, vector<ll>(n, -INF));
    ll ans = -INF;
    for(int v = 1; v <= n; v++){    //頂点v
        int now = v;
        ll tmp = 0;
        rep(i, uf.size(v)){ //i回移動
            tmp += c[now];
            score[uf.root(v)][i] = max(score[uf.root(v)][i], tmp);
            now = g[now];
        }
        tmp = 0;
        rep(i, uf.size(v)){
            if(i+1 > k) break;
            tmp = score[uf.root(v)][i];
            if(score[uf.root(v)][uf.size(uf.root(v))-1] > 0){
                ll e = (k-(i+1))/uf.size(v);
                tmp += score[uf.root(v)][uf.size(uf.root(v))-1]*e;
            }
            ans = max(ans, tmp);
        }
    cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:88:2: error: expected '}' at end of input
   88 | }
      |  ^
a.cc:54:11: note: to match this '{'
   54 | int main(){
      |           ^