Language: C++

bool dc(vector<pair<int, int>> &a, vector<int> &v, int t, int s, int i, int o, int p, int n) {
  v[i] = 1;
  for (int k = 0; k < a[k].size(); k++) {
  	if (v[a[k].first] == 0) {
      dc(a, v, t+1, s+a[k].second, a[k].first, o, p, n); 
    } else if (a[k].first == o) {
      if (s+a[k].second > t*p) return true;
    }
  }
  v[i] = 0;
  return true;
}

void q(vector<pair<int, int>> &a, vector<vector<int>> &pa, vector<int> &v, vector<int> &c, int &ans, int i, int t, int s, int p, int n) {
  if (i == n-1) {
    c.push_back(n-1);
    pa.push_back(c);
    c.pop_back();
    ans = max(ans, s - p*t);
    return;
  }
  v[i] = 1;
  c.push_back(i);
  for (int k = 0; k < a[k].size(); k++) {
  	if (v[a[k].first] == 0) {
      q(a, pa, v, c, ans, a[k].first, t+1, s+a[k].second, p, n); 
    }
  }
  v[i] = 0;
  c.pop_back();
}

int main() {
  int n, m, p;
  cin>>n>>m>>p;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < m; i++) {
    int s, e, v;
    cin>>s>>e>>v;
    s--;
    e--;
    a[s].push_back({e, v});
  }
  vector<int> v(n);
  vector<int> c;
  vector<vector<int>> pa;
  int ans = 0;
  q(a, pa, v, c, ans, 0, 0, 0, p, n);
  set<int> ss;
  for (int i = 0; i < pa.size(); i++) {
  	for (int j = 0; j < pa[i].size(); j++) {
      ss.insert(pa[i][j]);
    }
  }
  int fl = 0;
  for (int i = 0; i < ss.size(); i++) {
  	vector<int> nv(n);
    bool tt = dc(a, nv, 0, 0, ss[i], ss[i], p, n);
    if (tt == true) {
      fl = 1;
      cout<<-1<<endl;
      break;
    }
  }
  if (fl == 0) cout<<ans<<endl;
  return 0;
}

Compiler output:
a.cc:1:9: error: 'vector' was not declared in this scope
    1 | bool dc(vector<pair<int, int>> &a, vector<int> &v, int t, int s, int i, int o, int p, int n) {
      |         ^~~~~~
a.cc:1:16: error: 'pair' was not declared in this scope
    1 | bool dc(vector<pair<int, int>> &a, vector<int> &v, int t, int s, int i, int o, int p, int n) {
      |                ^~~~
a.cc:1:21: error: expected primary-expression before 'int'
    1 | bool dc(vector<pair<int, int>> &a, vector<int> &v, int t, int s, int i, int o, int p, int n) {
      |                     ^~~
a.cc:1:26: error: expected primary-expression before 'int'
    1 | bool dc(vector<pair<int, int>> &a, vector<int> &v, int t, int s, int i, int o, int p, int n) {
      |                          ^~~
a.cc:1:36: error: 'vector' was not declared in this scope
    1 | bool dc(vector<pair<int, int>> &a, vector<int> &v, int t, int s, int i, int o, int p, int n) {
      |                                    ^~~~~~
a.cc:1:43: error: expected primary-expression before 'int'
    1 | bool dc(vector<pair<int, int>> &a, vector<int> &v, int t, int s, int i, int o, int p, int n) {
      |                                           ^~~
a.cc:1:52: error: expected primary-expression before 'int'
    1 | bool dc(vector<pair<int, int>> &a, vector<int> &v, int t, int s, int i, int o, int p, int n) {
      |                                                    ^~~
a.cc:1:59: error: expected primary-expression before 'int'
    1 | bool dc(vector<pair<int, int>> &a, vector<int> &v, int t, int s, int i, int o, int p, int n) {
      |                                                           ^~~
a.cc:1:66: error: expected primary-expression before 'int'
    1 | bool dc(vector<pair<int, int>> &a, vector<int> &v, int t, int s, int i, int o, int p, int n) {
      |                                                                  ^~~
a.cc:1:73: error: expected primary-expression before 'int'
    1 | bool dc(vector<pair<int, int>> &a, vector<int> &v, int t, int s, int i, int o, int p, int n) {
      |                                                                         ^~~
a.cc:1:80: error: expected primary-expression before 'int'
    1 | bool dc(vector<pair<int, int>> &a, vector<int> &v, int t, int s, int i, int o, int p, int n) {
      |                                                                                ^~~
a.cc:1:87: error: expected primary-expression before 'int'
    1 | bool dc(vector<pair<int, int>> &a, vector<int> &v, int t, int s, int i, int o, int p, int n) {
      |                                                                                       ^~~
a.cc:1:92: error: expression list treated as compound expression in initializer [-fpermissive]
    1 | bool dc(vector<pair<int, int>> &a, vector<int> &v, int t, int s, int i, int o, int p, int n) {
      |                                                                                            ^
a.cc:14:6: error: variable or field 'q' declared void
   14 | void q(vector<pair<int, int>> &a, vector<vector<int>> &pa, vector<int> &v, vector<int> &c, int &ans, int i, int t, int s, int p, int n) {
      |      ^
a.cc:14:8: error: 'vector' was not declared in this scope
   14 | void q(vector<pair<int, int>> &a, vector<vector<int>> &pa, vector<int> &v, vector<int> &c, int &ans, int i, int t, int s, int p, int n) {
      |        ^~~~~~
a.cc:14:15: error: 'pair' was not declared in this scope
   14 | void q(vector<pair<int, int>> &a, vector<vector<int>> &pa, vector<int> &v, vector<int> &c, int &ans, int i, int t, int s, int p, int n) {
      |               ^~~~
a.cc:14:20: error: expected primary-expression before 'int'
   14 | void q(vector<pair<int, int>> &a, vector<vector<int>> &pa, vector<int> &v, vector<int> &c, int &ans, int i, int t, int s, int p, int n) {
      |                    ^~~
a.cc:14:25: error: expected primary-expression before 'int'
   14 | void q(vector<pair<int, int>> &a, vector<vector<int>> &pa, vector<int> &v, vector<int> &c, int &ans, int i, int t, int s, int p, int n) {
      |                         ^~~
a.cc:14:35: error: 'vector' was not declared in this scope
   14 | void q(vector<pair<int, int>> &a, vector<vector<int>> &pa, vector<int> &v, vector<int> &c, int &ans, int i, int t, int s, int p, int n) {
      |                                   ^~~~~~
a.cc:14:42: error: 'vector' was not declared in this scope
   14 | void q(vector<pair<int, int>> &a, vector<vector<int>> &pa, vector<int> &v, vector<int> &c, int &ans, int i, int t, int s, int p, int n) {
      |                                          ^~~~~~
a.cc:14:49: error: expected primary-expression before 'int'
   14 | void q(vector<pair<int, int>> &a, vector<vector<int>> &pa, vector<int> &v, vector<int> &c, int &ans, int i, int t, int s, int p, int n) {
      |                                                 ^~~
a.cc:14:60: error: 'vector' was not declared in this scope
   14 | void q(vector<pair<int, int>> &a, vector<vector<int>> &pa, vector<int> &v, vector<int> &c, int &ans, int i, int t, int s, int p, int n) {
      |                                                            ^~~~~~
a.cc:14:67: error: expected primary-expression before 'int'
   14 | void q(vector<pair<int, int>> &a, vector<vector<int>> &pa, vector<int> &v, vector<int> &c, int &ans, int i, int t, int s, int p, int n) {
      |                                                                   ^~~
a.cc:14:76: error: 'vector' was not declared in this scope
   14 | void q(vector<pair<int, int>> &a, vector<vector<int>> &pa, vector<int> &v, vector<int> &c, int &ans, int i, int t, int s, int p, int n) {
      |                                                                            ^~~~~~
a.cc:14:83: error: expected primary-expression before 'int'
   14 | void q(vector<pair<int, int>> &a, vector<vector<int>> &pa, vector<int> &v, vector<int> &c, int &ans, int i, int t, int s, int p, int n) {
      |                                                                                   ^~~
a.cc:14:92: error: expected primary-expression before 'int'
   14 | void q(vector<pair<int, int>> &a, vector<vector<int>> &pa, vector<int> &v, vector<int> &c, int &ans, int i, int t, int s, int p, int n) {
      |                                                                                            ^~~
a.cc:14:102: error: expected primary-expression before 'int'
   14 | void q(vector<pair<int, int>> &a, vector<vector<int>> &pa, vector<int> &v, vector<int> &c, int &ans, int i, int t, int s, int p, int n) {
      |                                                                                                      ^~~
a.cc:14:109: error: expected primary-expression before 'int'
   14 | void q(vector<pair<int, int>> &a, vector<vector<int>> &pa, vector<int> &v, vector<int> &c, int &ans, int i, int t, int s, int p, int n) {
      |                                                                                                             ^~~
a.cc:14:116: error: expected primary-expression before 'int'
   14 | void q(vector<pair<int, int>> &a, vector<vector<int>> &pa, vector<int> &v, vector<int> &c, int &ans, int i, int t, int s, int p, int n) {
      |                                                                                                                    ^~~
a.cc:14:123: error: expected primary-expression before 'int'
   14 | void q(vector<pair<int, int>> &a, vector<vector<int>> &pa, vector<int> &v, vector<int> &c, int &ans, int i, int t, int s, int p, int n) {
      |                                                                                                                           ^~~
a.cc:14:130: error: expected primary-expression before 'int'
   14 | void q(vector<pair<int, int>> &a, vector<vector<int>> &pa, vector<int> &v, vector<int> &c, int &ans, int i, int t, int s, int p, int n) {
      |                                                                                                                                  ^~~
a.cc: In function 'int main()':
a.cc:35:3: error: 'cin' was not declared in this scope
   35 |   cin>>n>>m>>p;
      |   ^~~
a.cc:36:3: error: 'vector' was not declared in this scope
   36 |   vector<pair<int, int>> a(n);
      |   ^~~~~~
a.cc:36:10: error: 'pair' was not declared in this scope
   36 |   vector<pair<int, int>> a(n);
      |          ^~~~
a.cc:36:15: error: expected primary-expression before 'int'
   36 |   vector<pair<int, int>> a(n);
      |               ^~~
a.cc:42:5: error: 'a' was not declared in this scope
   42 |     a[s].push_back({e, v});
      |     ^
a.cc:44:10: error: expected primary-expression before 'int'
   44 |   vector<int> v(n);
      |          ^~~
a.cc:45:10: error: expected primary-expression before 'int'
   45 |   vector<int> c;
      |          ^~~
a.cc:46:17: error: expected primary-expression before 'int'
   46 |   vector<vector<int>> pa;
      |                 ^~~
a.cc:48:5: error: 'a' was not declared in this scope
   48 |   q(a, pa, v, c, ans, 0, 0, 0, p, n);
      |     ^
a.cc:48:8: error: 'pa' was not declared in this scope; did you mean 'p'?
   48 |   q(a, pa, v, c, ans, 0, 0, 0, p, n);
      |        ^~
      |        p
a.cc:48:12: error: 'v' was not declared in this scope
   48 |   q(a, pa, v, c, ans, 0, 0, 0, p, n);
      |            ^
a.cc:48:15: error: 'c' was not declared in this scope
   48 |   q(a, pa, v, c, ans, 0, 0, 0, p, n);
      |               ^
a.cc:48:3: error: 'q' was not declared in this scope
   48 |   q(a, pa, v, c, ans, 0, 0, 0, p, n);
      |   ^
a.cc:49:3: error: 'set' was not declared in this scope
   49 |   set<int> ss;
      |   ^~~
a.cc:49:7: error: expected primary-expression before 'int'
   49 |   set<int> ss;
      |       ^~~
a.cc:52:7: error: 'ss' was not declared in this scope
   52 |       ss.insert(pa[i][j]);
      |       ^~
a.cc:56:23: error: 'ss' was not declared in this scope
   56 |   for (int i = 0; i < ss.size(); i++) {
      |                       ^~
a.cc:57:16: error: expected primary-expression before 'int'
   57 |         vector<int> nv(n);
      |                ^~~
a.cc:58:21: error: 'nv' was not declared in this scope; did you mean 'n'?
   58 |     bool tt = dc(a, nv, 0, 0, ss[i], ss[i], p,