Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
typedef vector<int> vi;
#define loop(i,a,b) for(int i=a; i<(int)(b); i++)
#define rep(i,n) loop(i,0,n)
#define all(c) (c).begin(), (c).end()
int n,m;
struct edge {
    int v,cost;
    edge(const edge &){}
    edge(int v,int cost):v(v),cost(cost){}
};

vector<vector<edge> > G;

int tord[400];
int _t=0;
vi ord;
bool used[410];
void tsort(int v){
    used[v]=1;
    rep(i,G[v].size()){
        int u=G[v][i].v;
        if(used[u])continue;
        tsort(u);
    }
    ord.push_back(v);
    tord[v]=_t++;
}

int dp[410];
int main(){
    memset(used,0,sizeof(used));
    memset(dp,0,sizeof(dp));
    cin>>n>>m;
    ord.reserve(n);
    G.resize(n);
    rep(i,m){
        int a,b,c;
        cin>>a>>b>>c;
        G[a].push_back((edge){b,c});
    }
    tsort(0);
    for(const auto&e:G){
        sort(all(e),[](const edge& a, const edge& b){
                return tord[a.v] > tord[b.v];
            });
    }
    reverse(all(ord));
    rep(i,n){
        rep(j,G[i].size()){
            const edge &e=G[i][j];
            dp[e.v]=max(dp[e.v],dp[i]+e.cost);
        }
    }
    cout<<dp[n-1]<<endl;
}

Compiler output:
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h: In instantiation of 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(const edge&, const edge&)> >]':
/usr/include/c++/14/bits/stl_algo.h:1817:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(const edge&, const edge&)> >]'
 1817 |           std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(const edge&, const edge&)> >]'
 1908 |           std::__final_insertion_sort(__first, __last, __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4805:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<const edge*, vector<edge> >; _Compare = main()::<lambda(const edge&, const edge&)>]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:48:13:   required from here
   48 |         sort(all(e),[](const edge& a, const edge& b){
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   49 |                 return tord[a.v] > tord[b.v];
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   50 |             });
      |             ~~
/usr/include/c++/14/bits/stl_algo.h:1782:24: error: passing 'const edge' as 'this' argument discards qualifiers [-fpermissive]
 1782 |               *__first = _GLIBCXX_MOVE(__val);
      |                        ^
a.cc:11:8: note:   in call to 'constexpr edge& edge::operator=(const edge&)'
   11 | struct edge {
      |        ^~~~
In file included from /usr/include/c++/14/bits/stl_algo.h:61:
/usr/include/c++/14/bits/stl_heap.h: In instantiation of 'void std::__pop_heap(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(const edge&, const edge&)> >]':
/usr/include/c++/14/bits/stl_algo.h:1596:19:   required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(const edge&, const edge&)> >]'
 1596 |           std::__pop_heap(__first, __middle, __i, __comp);
      |           ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1868:25:   required from 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(const edge&, const edge&)> >]'
 1868 |       std::__heap_select(__first, __middle, __last, __comp);
      |       ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1884:27:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const edge*, vector<edge> >; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(const edge&, const edge&)> >]'
 1884 |               std::__partial_sort(__first, __last, __last, __comp);
      |               ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1905:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(const edge&, const edge&)> >]'
 1905 |           std::__introsort_loop(__first, __last,
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
 1906 |                                 std::__lg(__last - __first) * 2,
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1907 |                                 __comp);
      |                                 ~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4805:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<const edge*, vector<edge> >; _Compare = main()::<lambda(const edge&, const edge&)>]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:48:13:   required from here
   48 |         sort(all(e),[](const edge& a, const edge& b){
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   49 |                 return tord[a.v] > tord[b.v];
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   50 |             });
      |             ~~
/usr/include/c++/14/bits/stl_heap.h:263:17: error: passing 'const edge' as 'this' argument discards qualifiers [-fpermissive]
  263 |       *__result = _GLIBCXX_MOVE(*__first);
      |                 ^
a.cc:11:8: note:   in call to 'constexpr edge& edge::operator=(const edge&)'
   11 | struct edge {
      |        ^~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = __gnu_cxx::__normal_iterator<const edge*, vector<edge> >; _ForwardIterator2 = __gnu_cxx::__normal_iterator<const edge*, vector<edge> >]':
/usr/include/c++/14/bits/stl_algo.h:91:20:   required from 'void std::__move_median_to_first(_Iterator, _Iterator, _Iterator, _Iterator, _Compare) [with _Iterator = __gnu_cxx::__normal_iterator<const edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(const edge&, const edge&)> >]'
   91 |             std::iter_swap(__result, __b);
      |             ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1855:34:   required from '_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(const edge&, const edge&)> >]'
 1855 |       std::__move_median_to_first(__first, __first + 1, __mid, __last - 1,
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1856 |                                   __comp);
      |                                   ~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1889:38:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const edge*, vector<edge> >; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(const edge&, const edge&)> >]'
 1889 |             std::__unguarded_partition_pivot(__first, __last, __comp);
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1905:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(const edge&, const edge&)> >]'
 1905 |           std::__introsort_loop(__first, __last,
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
 1906 |                                 std::__lg(__last - __first) * 2,
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1907 |                                 __comp);
      |                                 ~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4805:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<const edge*, vector<edge> >; _Compare = main()::<lambda(const edge&, const edge&)>]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:48:13:   required from here
   48 |         sort(all(e),[](const edge& a, const edge& b){
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   49 |                 return tord[a.v] > tord[b.v];
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   50 |             });
      |             ~~
/usr/include/c++/14/bits/stl_algobase.h:185:11: error: no matching function for call to 'swap(const edge&, const edge&)'
  185 |       swap(*__a, *__b);
      |       ~~~~^~~~~~~~~~~~
In file included from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41:
/usr/include/c++/14/bits/exception_ptr.h:229:5: note: candidate: 'void std::__exception_ptr::swap(exception_ptr&, exception_ptr&)'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
/usr/include/c++/14/bits/exception_ptr.h:229:25: note:   no known conversion for argument 1 from 'const edge' to 'std::__exception_ptr::except