Language: C++

constexpr int MAX_N = 2525;
 constexpr LL INF = 1e15;
 
 vector<int> go[MAX_N];
 vector<int> back[MAX_N];
 vector<bool> go_state(MAX_N, false);
 vector<bool> back_state(MAX_N, false);
 
 void dfs(int v, vector<int> way[], vector<bool> &state) {
     if (state[v])return;
     state[v] = true;
     for (auto to: way[v]) {
         dfs(to, way, state);
     }
 }
 
 
 int main() {
 
     int N, M, P;
     cin >> N >> M >> P;
 
     vector<int> A(M), B(M), C(M);
     vector<tuple<int, int, int>> edges(M);
     for (int i = 0; i < M; i++) {
         cin >> A[i] >> B[i] >> C[i];
         A[i]--, B[i]--;
         C[i] -= P;
         edges[i] = make_tuple(A[i], B[i], C[i]);
         go[A[i]].push_back(B[i]);
         back[B[i]].push_back(A[i]);
     }
 
     dfs(0, go, go_state);
     dfs(N - 1, back, back_state);
 
     vector<bool> sects(MAX_N, false);
     for (int i = 0; i < N; i++) sects[i] = go_state[i] & back_state[i];
 
     vector<LL> dist(N, -INF);
     dist[0] = 0;
     for (int i = 0; i < N; i++) {
         for (auto &e: edges) {
             int a, b, c;
             tie(a, b, c) = e;
             if (dist[a] != -INF) {
                 dist[b] = max(dist[b], dist[a] + c);
             }
         }
     }
 
     auto cp = dist;
     for (int i = 0; i < N; i++) {
         for (auto &e: edges) {
             int a, b, c;
             tie(a, b, c) = e;
             if (dist[a] != -INF) {
                 dist[b] = max(dist[b], dist[a] + c);
             }
         }
     }
 
     for (int i = 0; i < N; i++) {
         if (sects[i] && (cp[i] != dist[i])) {
             cout << -1 << endl;
             return 0;
         }
     }
 
     cout << max(0LL, dist[N - 1]) << endl;
 
 }
 

Compiler output:
a.cc:2:12: error: 'LL' does not name a type
    2 |  constexpr LL INF = 1e15;
      |            ^~
a.cc:4:2: error: 'vector' does not name a type
    4 |  vector<int> go[MAX_N];
      |  ^~~~~~
a.cc:5:2: error: 'vector' does not name a type
    5 |  vector<int> back[MAX_N];
      |  ^~~~~~
a.cc:6:2: error: 'vector' does not name a type
    6 |  vector<bool> go_state(MAX_N, false);
      |  ^~~~~~
a.cc:7:2: error: 'vector' does not name a type
    7 |  vector<bool> back_state(MAX_N, false);
      |  ^~~~~~
a.cc:9:18: error: 'vector' has not been declared
    9 |  void dfs(int v, vector<int> way[], vector<bool> &state) {
      |                  ^~~~~~
a.cc:9:24: error: expected ',' or '...' before '<' token
    9 |  void dfs(int v, vector<int> way[], vector<bool> &state) {
      |                        ^
a.cc: In function 'void dfs(int, int)':
a.cc:10:10: error: 'state' was not declared in this scope; did you mean 'static'?
   10 |      if (state[v])return;
      |          ^~~~~
      |          static
a.cc:11:6: error: 'state' was not declared in this scope; did you mean 'static'?
   11 |      state[v] = true;
      |      ^~~~~
      |      static
a.cc:12:20: error: 'way' was not declared in this scope
   12 |      for (auto to: way[v]) {
      |                    ^~~
a.cc: In function 'int main()':
a.cc:21:6: error: 'cin' was not declared in this scope
   21 |      cin >> N >> M >> P;
      |      ^~~
a.cc:23:6: error: 'vector' was not declared in this scope
   23 |      vector<int> A(M), B(M), C(M);
      |      ^~~~~~
a.cc:23:13: error: expected primary-expression before 'int'
   23 |      vector<int> A(M), B(M), C(M);
      |             ^~~
a.cc:24:13: error: 'tuple' was not declared in this scope
   24 |      vector<tuple<int, int, int>> edges(M);
      |             ^~~~~
a.cc:24:19: error: expected primary-expression before 'int'
   24 |      vector<tuple<int, int, int>> edges(M);
      |                   ^~~
a.cc:26:17: error: 'A' was not declared in this scope
   26 |          cin >> A[i] >> B[i] >> C[i];
      |                 ^
a.cc:26:25: error: 'B' was not declared in this scope
   26 |          cin >> A[i] >> B[i] >> C[i];
      |                         ^
a.cc:26:33: error: 'C' was not declared in this scope
   26 |          cin >> A[i] >> B[i] >> C[i];
      |                                 ^
a.cc:29:10: error: 'edges' was not declared in this scope
   29 |          edges[i] = make_tuple(A[i], B[i], C[i]);
      |          ^~~~~
a.cc:29:21: error: 'make_tuple' was not declared in this scope
   29 |          edges[i] = make_tuple(A[i], B[i], C[i]);
      |                     ^~~~~~~~~~
a.cc:30:10: error: 'go' was not declared in this scope
   30 |          go[A[i]].push_back(B[i]);
      |          ^~
a.cc:31:10: error: 'back' was not declared in this scope
   31 |          back[B[i]].push_back(A[i]);
      |          ^~~~
a.cc:34:13: error: 'go' was not declared in this scope
   34 |      dfs(0, go, go_state);
      |             ^~
a.cc:34:17: error: 'go_state' was not declared in this scope
   34 |      dfs(0, go, go_state);
      |                 ^~~~~~~~
a.cc:35:17: error: 'back' was not declared in this scope
   35 |      dfs(N - 1, back, back_state);
      |                 ^~~~
a.cc:35:23: error: 'back_state' was not declared in this scope
   35 |      dfs(N - 1, back, back_state);
      |                       ^~~~~~~~~~
a.cc:37:13: error: expected primary-expression before 'bool'
   37 |      vector<bool> sects(MAX_N, false);
      |             ^~~~
a.cc:38:34: error: 'sects' was not declared in this scope
   38 |      for (int i = 0; i < N; i++) sects[i] = go_state[i] & back_state[i];
      |                                  ^~~~~
a.cc:40:13: error: 'LL' was not declared in this scope
   40 |      vector<LL> dist(N, -INF);
      |             ^~
a.cc:40:26: error: 'INF' was not declared in this scope
   40 |      vector<LL> dist(N, -INF);
      |                          ^~~
a.cc:40:17: error: 'dist' was not declared in this scope
   40 |      vector<LL> dist(N, -INF);
      |                 ^~~~
a.cc:43:24: error: 'edges' was not declared in this scope
   43 |          for (auto &e: edges) {
      |                        ^~~~~
a.cc:45:14: error: 'tie' was not declared in this scope
   45 |              tie(a, b, c) = e;
      |              ^~~
a.cc:47:28: error: 'max' was not declared in this scope
   47 |                  dist[b] = max(dist[b], dist[a] + c);
      |                            ^~~
a.cc:54:24: error: 'edges' was not declared in this scope
   54 |          for (auto &e: edges) {
      |                        ^~~~~
a.cc:56:14: error: 'tie' was not declared in this scope
   56 |              tie(a, b, c) = e;
      |              ^~~
a.cc:58:28: error: 'max' was not declared in this scope
   58 |                  dist[b] = max(dist[b], dist[a] + c);
      |                            ^~~
a.cc:64:14: error: 'sects' was not declared in this scope
   64 |          if (sects[i] && (cp[i] != dist[i])) {
      |              ^~~~~
a.cc:65:14: error: 'cout' was not declared in this scope
   65 |              cout << -1 << endl;
      |              ^~~~
a.cc:65:28: error: 'endl' was not declared in this scope
   65 |              cout << -1 << endl;
      |                            ^~~~
a.cc:70:6: error: 'cout' was not declared in this scope
   70 |      cout << max(0LL, dist[N - 1]) << endl;
      |      ^~~~
a.cc:70:14: error: 'max' was not declared in this scope
   70 |      cout << max(0LL, dist[N - 1]) << endl;
      |              ^~~
a.cc:70:39: error: 'endl' was not declared in this scope
   70 |      cout << max(0LL, dist[N - 1]) << endl;
      |                                       ^~~~