Language: C++

#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
vll to[2505];
vll rto[2505];
vb from1[2505];
vb fromn[2505];
void dfs(ll v){
  if(from1[v]) return ;
  from1[v]=true;
  for(auto p:to[v]){
    dfs(p);
  }
}
void rdfs(ll v){
  if(fromn[v]) return ;
  fromn[v]=true;
  for(auto p:rto[v]){
    rdfs(p);
  }
}
int main(){
  ll n,m,p;
  cin>>n>>m>>p;
  vector<tuple<ll,ll,ll>> edges;
  rep(i,m){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;
    b--;
    c-=p;
    c*=-1;
    edges.emplace_back(a,b,c);
    to[a].pb(b);
    rto[b].pb(a);
  }
  dfs(0);
  rdfs(n-1);
  bool ok[2505];
  rep(i,n) ok[i]=from1[i]&fromn[i];
  vll d(n,INF);
  d[0]=0;
  bool udt=true;
  ll cu=0;
  while(udt){
    udt=false;
    rep(i,m){
      ll a,b,c;
      tie(a,b,c)=edges[i];
      if(!ok[a]||!ok[b]) continue;
      if(d[a]+c<d[b]){
        d[b]=d[a]+c;
        udt=true;
      }
    }
    cu++;
    if(cu>n){
      COUT(-1);
      return 0;
    }
  }
  COUT(max(-d[n-1],0));
}
  


Compiler output:
a.cc: In function 'void dfs(long long int)':
a.cc:51:13: error: could not convert 'from1[v]' from 'vb' {aka 'std::vector<bool>'} to 'bool'
   51 |   if(from1[v]) return ;
      |      ~~~~~~~^
      |             |
      |             vb {aka std::vector<bool>}
a.cc:52:12: error: no match for 'operator=' (operand types are 'vb' {aka 'std::vector<bool>'} and 'bool')
   52 |   from1[v]=true;
      |            ^~~~
In file included from /usr/include/c++/14/vector:67,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_bvector.h:894:7: note: candidate: 'std::vector<bool, _Alloc>& std::vector<bool, _Alloc>::operator=(const std::vector<bool, _Alloc>&) [with _Alloc = std::allocator<bool>]'
  894 |       operator=(const vector& __x)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_bvector.h:894:31: note:   no known conversion for argument 1 from 'bool' to 'const std::vector<bool>&'
  894 |       operator=(const vector& __x)
      |                 ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_bvector.h:926:7: note: candidate: 'std::vector<bool, _Alloc>& std::vector<bool, _Alloc>::operator=(std::vector<bool, _Alloc>&&) [with _Alloc = std::allocator<bool>]'
  926 |       operator=(vector&& __x) noexcept(_Bit_alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_bvector.h:926:26: note:   no known conversion for argument 1 from 'bool' to 'std::vector<bool>&&'
  926 |       operator=(vector&& __x) noexcept(_Bit_alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_bvector.h:952:7: note: candidate: 'std::vector<bool, _Alloc>& std::vector<bool, _Alloc>::operator=(std::initializer_list<bool>) [with _Alloc = std::allocator<bool>]'
  952 |       operator=(initializer_list<bool> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_bvector.h:952:40: note:   no known conversion for argument 1 from 'bool' to 'std::initializer_list<bool>'
  952 |       operator=(initializer_list<bool> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc: In function 'void rdfs(long long int)':
a.cc:58:13: error: could not convert 'fromn[v]' from 'vb' {aka 'std::vector<bool>'} to 'bool'
   58 |   if(fromn[v]) return ;
      |      ~~~~~~~^
      |             |
      |             vb {aka std::vector<bool>}
a.cc:59:12: error: no match for 'operator=' (operand types are 'vb' {aka 'std::vector<bool>'} and 'bool')
   59 |   fromn[v]=true;
      |            ^~~~
/usr/include/c++/14/bits/stl_bvector.h:894:7: note: candidate: 'std::vector<bool, _Alloc>& std::vector<bool, _Alloc>::operator=(const std::vector<bool, _Alloc>&) [with _Alloc = std::allocator<bool>]'
  894 |       operator=(const vector& __x)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_bvector.h:894:31: note:   no known conversion for argument 1 from 'bool' to 'const std::vector<bool>&'
  894 |       operator=(const vector& __x)
      |                 ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_bvector.h:926:7: note: candidate: 'std::vector<bool, _Alloc>& std::vector<bool, _Alloc>::operator=(std::vector<bool, _Alloc>&&) [with _Alloc = std::allocator<bool>]'
  926 |       operator=(vector&& __x) noexcept(_Bit_alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_bvector.h:926:26: note:   no known conversion for argument 1 from 'bool' to 'std::vector<bool>&&'
  926 |       operator=(vector&& __x) noexcept(_Bit_alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_bvector.h:952:7: note: candidate: 'std::vector<bool, _Alloc>& std::vector<bool, _Alloc>::operator=(std::initializer_list<bool>) [with _Alloc = std::allocator<bool>]'
  952 |       operator=(initializer_list<bool> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_bvector.h:952:40: note:   no known conversion for argument 1 from 'bool' to 'std::initializer_list<bool>'
  952 |       operator=(initializer_list<bool> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc: In function 'int main()':
a.cc:82:26: error: no match for 'operator&' (operand types are 'vb' {aka 'std::vector<bool>'} and 'vb' {aka 'std::vector<bool>'})
   82 |   rep(i,n) ok[i]=from1[i]&fromn[i];
      |                  ~~~~~~~~^~~~~~~~~
      |                         |        |
      |                         |        vector<[...]>
      |                         vector<[...]>
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bitset:1557:5: note: candidate: 'template<long unsigned int _Nb> std::bitset<_Nb> std::operator&(const bitset<_Nb>&, const bitset<_Nb>&)'
 1557 |     operator&(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
      |     ^~~~~~~~
/usr/include/c++/14/bitset:1557:5: note:   template argument deduction/substitution failed:
a.cc:82:34: note:   'vb' {aka 'std::vector<bool>'} is not derived from 'const std::bitset<_Nb>'
   82 |   rep(i,n) ok[i]=from1[i]&fromn[i];
      |                                  ^
In file included from /usr/include/c++/14/valarray:605,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166:
/usr/include/c++/14/bits/valarray_after.h:411:5: note: candidate: 'template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__bitwise_and, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__bitwise_and, typename _Dom1::value_type>::result_type> std::operator&(const _Expr<_Dom1, typename _Dom1::value_type>&, const _Expr<_Dom2, typename _Dom2::value_type>&)'
  411 |     _DEFINE_EXPR_BINARY_OPERATOR(&, struct std::__bitwise_and)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:411:5: note:   template argument deduction/substitution failed:
a.cc:82:34: note:   'vb' {aka 'std::vector<bool>'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   82 |   rep(i,n) ok[i]=from1[i]&fromn[i];
      |                                  ^
/usr/include/c++/14/bits/valarray_after.h:411:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__bitwise_and, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__bitwise_and, typename _Dom1::value_type>::result_type> std::operator&(const _Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)'
  411 |     _DEFINE_EXPR_BINARY_OPERATOR(&, struct std::__bitwise_and)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:411:5: note:   template argument deduction/substitution failed:
a.cc:82:34: note:   'vb' {aka 'std::vector<bool>'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   82 |   rep(i,n) ok[i]=from1[i]&fromn[i];
      |                                  ^
/usr/include/c++/14/bits/valarray_after.h:411:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__bitwise_and, std::_Constant, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__bitwise_and, typename _Dom1::value_type>::result_type> std::operator&(const typename _Dom::value_type&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  411 |     _DEFINE_EXPR_BINARY_OPERATOR(&, struct std::__bitwise_and)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:411:5: note:   template argument deduction/substitution failed:
a.cc:82:34: note:   'vb' {aka 'std::vector<bool>'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   82 |   rep(i,n) ok[i]=from1[i]&fromn[i];
      |                                  ^
/usr/include/c++/14/bits/valarray_after.h:411:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__bitwise_and, std::_Expr, std::_ValArray, _Dom, typename _Dom::value_type>, typename std::__fun<std::__bitwise_and, typename _Dom1::value_type>::result_type> std::operator&(const _Expr<_Dom1, typename _Dom1::value_type>&, const valarray<typename _Dom::value_type>&)'
  411 |     _DEFINE_EXPR_BINARY_OPERATOR(&, struct std::__bitwise_and)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:411:5: note:   template argument deduction/substitution failed:
a.cc:82:34: note:   'vb' {aka 'std::vector<bool>'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   82 |   rep(i,n) ok[i]=from1[i]&fromn[i];
      |                                  ^
/usr/include/c++/14/bits/valarray_after.h:411:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__bitwise_and, std::_ValArray, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__bitwise_and, typename _Dom1::value_type>::result_type> std::operator&(const valarray<typename _Dom::value_type>&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  411 |     _DEFINE_EXPR_BINARY_OPERATOR(&, struct std::__bitwise_and)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:411:5: note:   template argument deduction/substitution failed:
a.cc:82:34: note:   'vb' {aka 'std::vector<bool>'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   82 |   rep(i,n) ok[i]=from1[i]&fromn[i];
      |                                  ^
/usr/include/c++/14/valarray:1202:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__bitwise_and, std::_ValArray, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__bitwise_and, _Tp>::result_type> std::operator&(const valarray<_Tp>&, const valarray<_Tp>&)'
 1202 | _DEFINE_BINARY_OPERATOR(&, __bitwise_and)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1202:1: note:   template argument deduction/substitution failed:
a.cc:82:34: note:   'vb' {aka 'std::vector<bool>'} is not derived from 'const std::valarray<_Tp>'
   82 |   rep(i,n) ok[i]=from1[i]&fromn[i];
      |                                  ^
/usr/include/c++/14/valarray:1202:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__bitwise_and, std::_ValArray, std::_Constant, _Tp, _Tp>, typename std::__fun<std::