Language: C++

atcoder-tools: The pre-rendered templates are not found.#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
void solve(long long N, long long K, std::vector<long long> P, std::vector<long long> C){
    Graph G(N);
    vector<bool> reached(N,false);
    stack<pair<long long,long long>> st;
    for (int i = 0;i<N;i++){
        int a = P[i];
        G[i].push_back(a);
    }
    ll ans1=-100000000000000000;
    for (int v =0;v<N;v++){
        ll ans =0;
        if(reached[v]) continue;
        st.emplace(make_pair(v,0));
        vector<pair<ll,ll>> dis;
        while(st.size()!=0){
            pair<long long,long long> p1= st.top();
            st.pop();
            long long v1 = p1.first;
            reached[v1]=true;
            long long dis1 = p1.second;
            dis.push_back(make_pair(v1,dis1));
            if(! reached[P[v1]-1]){
                st.emplace(make_pair(P[v1]-1,dis1+C[P[v1]-1]));
            }
        }
        long long index = dis.size();
        pair<ll,ll> pl =dis[index-1];
        ll dismax=pl.second+C[v];//ループの計算
        ll cycle = index;
        ll ncycle = K/cycle;
        ll amari = K%cycle;
        if(dismax>0){
            for(int k=0;k<index;k++){
                int l = k;
                ans = ncycle*dismax;
                ll b2=0;
                ll b3=0;
                for(int h=1;h<min(index,K);h++){
                    if(h<=amari){
                        b2+=C[dis[(l+h)%cycle].first];
                    }
                    b3 +=C[dis[(l+h)%cycle].first];
                    ans1 = max(ans1,ans+b2);
                    ans1 = max(ans1,ans-dismax+b3);
                }
            }
        }
        else{
            for(int k=0;k<index;k++){
                ans = 0;
                ll b2=0;
                ll b3=0;
                for(int h=1;h<min(index,K);h++){
                    b3 +=C[dis[(k+h)%cycle].first];
                    ans1 = max(ans1,b3);
                }
                //cout<<b3<<endl;
            }
        }
    }
    cout<<ans1<<endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> P(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&P[i]);
    }
    std::vector<long long> C(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&C[i]);
    }
    solve(N, K, std::move(P), std::move(C));
    return 0;
}


Compiler output:
a.cc:1:57: error: stray '#' in program
    1 | atcoder-tools: The pre-rendered templates are not found.#include <bits/stdc++.h>
      |                                                         ^
a.cc:1:1: error: 'atcoder' does not name a type
    1 | atcoder-tools: The pre-rendered templates are not found.#include <bits/stdc++.h>
      | ^~~~~~~
a.cc:3:15: error: 'vector' does not name a type
    3 | using Graph = vector<vector<int>>;
      |               ^~~~~~
a.cc:5:38: error: 'std::vector' has not been declared
    5 | void solve(long long N, long long K, std::vector<long long> P, std::vector<long long> C){
      |                                      ^~~
a.cc:5:49: error: expected ',' or '...' before '<' token
    5 | void solve(long long N, long long K, std::vector<long long> P, std::vector<long long> C){
      |                                                 ^
a.cc: In function 'void solve(long long int, long long int, int)':
a.cc:6:5: error: 'Graph' was not declared in this scope
    6 |     Graph G(N);
      |     ^~~~~
a.cc:7:5: error: 'vector' was not declared in this scope
    7 |     vector<bool> reached(N,false);
      |     ^~~~~~
a.cc:7:12: error: expected primary-expression before 'bool'
    7 |     vector<bool> reached(N,false);
      |            ^~~~
a.cc:8:5: error: 'stack' was not declared in this scope
    8 |     stack<pair<long long,long long>> st;
      |     ^~~~~
a.cc:8:11: error: 'pair' was not declared in this scope
    8 |     stack<pair<long long,long long>> st;
      |           ^~~~
a.cc:8:16: error: expected primary-expression before 'long'
    8 |     stack<pair<long long,long long>> st;
      |                ^~~~
a.cc:10:17: error: 'P' was not declared in this scope
   10 |         int a = P[i];
      |                 ^
a.cc:11:9: error: 'G' was not declared in this scope
   11 |         G[i].push_back(a);
      |         ^
a.cc:16:12: error: 'reached' was not declared in this scope
   16 |         if(reached[v]) continue;
      |            ^~~~~~~
a.cc:17:9: error: 'st' was not declared in this scope; did you mean 'std'?
   17 |         st.emplace(make_pair(v,0));
      |         ^~
      |         std
a.cc:17:20: error: 'make_pair' was not declared in this scope
   17 |         st.emplace(make_pair(v,0));
      |                    ^~~~~~~~~
a.cc:18:23: error: expected primary-expression before ',' token
   18 |         vector<pair<ll,ll>> dis;
      |                       ^
a.cc:18:26: error: expected primary-expression before '>>' token
   18 |         vector<pair<ll,ll>> dis;
      |                          ^~
a.cc:18:29: error: 'dis' was not declared in this scope
   18 |         vector<pair<ll,ll>> dis;
      |                             ^~~
a.cc:20:18: error: expected primary-expression before 'long'
   20 |             pair<long long,long long> p1= st.top();
      |                  ^~~~
a.cc:22:28: error: 'p1' was not declared in this scope; did you mean 'v1'?
   22 |             long long v1 = p1.first;
      |                            ^~
      |                            v1
a.cc:23:13: error: 'reached' was not declared in this scope
   23 |             reached[v1]=true;
      |             ^~~~~~~
a.cc:26:26: error: 'P' was not declared in this scope
   26 |             if(! reached[P[v1]-1]){
      |                          ^
a.cc:27:51: error: 'C' was not declared in this scope
   27 |                 st.emplace(make_pair(P[v1]-1,dis1+C[P[v1]-1]));
      |                                                   ^
a.cc:31:16: error: expected primary-expression before ',' token
   31 |         pair<ll,ll> pl =dis[index-1];
      |                ^
a.cc:31:19: error: expected primary-expression before '>' token
   31 |         pair<ll,ll> pl =dis[index-1];
      |                   ^
a.cc:31:21: error: 'pl' was not declared in this scope; did you mean 'll'?
   31 |         pair<ll,ll> pl =dis[index-1];
      |                     ^~
      |                     ll
a.cc:32:29: error: 'C' was not declared in this scope
   32 |         ll dismax=pl.second+C[v];//ループの計算
      |                             ^
a.cc:42:31: error: 'min' was not declared in this scope
   42 |                 for(int h=1;h<min(index,K);h++){
      |                               ^~~
a.cc:47:28: error: 'max' was not declared in this scope
   47 |                     ans1 = max(ans1,ans+b2);
      |                            ^~~
a.cc:57:31: error: 'min' was not declared in this scope
   57 |                 for(int h=1;h<min(index,K);h++){
      |                               ^~~
a.cc:59:28: error: 'max' was not declared in this scope
   59 |                     ans1 = max(ans1,b3);
      |                            ^~~
a.cc:65:5: error: 'cout' was not declared in this scope
   65 |     cout<<ans1<<endl;
      |     ^~~~
a.cc:65:17: error: 'endl' was not declared in this scope
   65 |     cout<<ans1<<endl;
      |                 ^~~~
a.cc: In function 'int main()':
a.cc:71:5: error: 'scanf' was not declared in this scope
   71 |     scanf("%lld",&N);
      |     ^~~~~
a.cc:74:10: error: 'vector' is not a member of 'std'
   74 |     std::vector<long long> P(N);
      |          ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | atcoder-tools: The pre-rendered templates are not found.#include <bits/stdc++.h>
a.cc:74:17: error: expected primary-expression before 'long'
   74 |     std::vector<long long> P(N);
      |                 ^~~~
a.cc:76:23: error: 'P' was not declared in this scope
   76 |         scanf("%lld",&P[i]);
      |                       ^
a.cc:78:10: error: 'vector' is not a member of 'std'
   78 |     std::vector<long long> C(N);
      |          ^~~~~~
a.cc:78:10: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:78:17: error: expected primary-expression before 'long'
   78 |     std::vector<long long> C(N);
      |                 ^~~~
a.cc:80:23: error: 'C' was not declared in this scope
   80 |         scanf("%lld",&C[i]);
      |                       ^
a.cc:82:22: error: 'move' is not a member of 'std'
   82 |     solve(N, K, std::move(P), std::move(C));
      |                      ^~~~
a.cc:1:1: note: 'std::move' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
  +++ |+#include <utility>
    1 | atcoder-tools: The pre-rendered templates are not found.#include <bits/stdc++.h>
a.cc:82:27: error: 'P' was not declared in this scope
   82 |     solve(N, K, std::move(P), std::move(C));
      |                           ^
a.cc:82:36: error: 'move' is not a member of 'std'
   82 |     solve(N, K, std::move(P), std::move(C));
      |                                    ^~~~
a.cc:82:36: note: 'std::move' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
a.cc:82:41: error: 'C' was not declared in this scope
   82 |     solve(N, K, std::move(P), std::move(C));
      |                                         ^