Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MAX = 1e+15;

typedef struct{
  ll s;
  ll t;
  ll c;
} edge;
 
ll n,m;
vector<vector<edge>> g,ig,subg;
 
ll longest_path() {
  vector<int> indeg(n,0);
  for(auto es : subg) {
    for(auto e : es) {
      indeg[e.t]++;
    }
  }
  stack<int> L; L.push(0);
  vector<ll> ans(n,0);
  while(1) {
    if( L.size() == 0 ) break;
    int v = L.top(); L.pop();        
    for(auto e : sung[v]) {
      indeg[e.t]--;
      if( indeg[e.t] == 0 ) L.push(e.t);
      ans[e.t] = max(ans[e.t],ans[v] + e.c);
    }
  }
  if( indeg[n-1] == 0 )
    return ans[n-1];
  else
    return MAX;

}

void dfs(int n,vector<vector<edge>>& graph, vector<int>& is_traverced, set<edge> res ){
 
  is_traverced[n] = 1;
  for(auto e : graph[n]) {
    res.insert(e);
   	if( is_traverced[e.t] == 1 ) continue;
    dfs(e.t, graph, is_traverced, res);
  }
  
}

set<edge> traverce(int n, vector<vector<edge>>& graph ) {
  set<edge> res;
  vector<int> is_traverced(n,0);
  dfs(n,graph,is_traverced,res);
  return res;
}
     
     
void make_subg(){
  
  set<edge> sn = traverse(0,g);
  set<edge> tn = traverse(n-1,ig);
  
  for(auto e : sn) 
  	if( tn.count({e.t, e.s, e.c} != 0 )
       subg[e.s].push_back(e);
  
  return;   
}
ll solve(){
 
  // 1-Nパスに含まれる頂点からなる部分グラフ
  make_subg();
    
  // 上記グラフがDAGか否か
  return longest_path();
}
 
int main() {
 
  cin >> n >> m;
  g = vector<vector<edge>>(n);
  ig= vector<vector<edge>>(n);
  for(int i=0; i<n; i++) {
    ll a,b,c; cin >> a >> b >> c;
    a--;b--;
    g[a].push_back({a,b,c});
    ig[b].push_back({b,a,c});
  }
  
  cout << (solve()==MAX ? "inf" : solve()) << endl;
  
}

Compiler output:
a.cc: In function 'll longest_path()':
a.cc:27:18: error: 'sung' was not declared in this scope; did you mean 'subg'?
   27 |     for(auto e : sung[v]) {
      |                  ^~~~
      |                  subg
a.cc: In function 'void make_subg()':
a.cc:61:18: error: 'traverse' was not declared in this scope; did you mean 'traverce'?
   61 |   set<edge> sn = traverse(0,g);
      |                  ^~~~~~~~
      |                  traverce
a.cc:65:37: error: expected ')' before '!=' token
   65 |         if( tn.count({e.t, e.s, e.c} != 0 )
      |                     ~               ^~~
      |                                     )
a.cc:65:44: error: expected ';' before 'subg'
   65 |         if( tn.count({e.t, e.s, e.c} != 0 )
      |                                            ^
      |                                            ;
   66 |        subg[e.s].push_back(e);
      |        ~~~~                                 
a.cc:68:3: error: expected primary-expression before 'return'
   68 |   return;
      |   ^~~~~~
a.cc:66:31: error: expected ')' before 'return'
   66 |        subg[e.s].push_back(e);
      |                               ^
      |                               )
   67 | 
   68 |   return;
      |   ~~~~~~                       
a.cc:65:11: note: to match this '('
   65 |         if( tn.count({e.t, e.s, e.c} != 0 )
      |           ^
a.cc: In function 'int main()':
a.cc:91:25: error: operands to '?:' have different types 'const char*' and 'll' {aka 'long long int'}
   91 |   cout << (solve()==MAX ? "inf" : solve()) << endl;
      |            ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:49,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_function.h: In instantiation of 'constexpr bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = edge]':
/usr/include/c++/14/bits/stl_tree.h:2545:33:   required from 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::find(const _Key&) const [with _Key = edge; _Val = edge; _KeyOfValue = std::_Identity<edge>; _Compare = std::less<edge>; _Alloc = std::allocator<edge>; const_iterator = std::_Rb_tree<edge, edge, std::_Identity<edge>, std::less<edge>, std::allocator<edge> >::const_iterator]'
 2545 |               || _M_impl._M_key_compare(__k,
      |                  ~~~~~~~~~~~~~~~~~~~~~~^~~~~
 2546 |                                         _S_key(__j._M_node))) ? end() : __j;
      |                                         ~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:751:25:   required from 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::count(const key_type&) const [with _Key = edge; _Compare = std::less<edge>; _Alloc = std::allocator<edge>; size_type = long unsigned int; key_type = edge]'
  751 |       { return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
      |                ~~~~~~~~~^~~~~
a.cc:65:16:   required from here
   65 |         if( tn.count({e.t, e.s, e.c} != 0 )
      |             ~~~~~~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_function.h:405:20: error: no match for 'operator<' (operand types are 'const edge' and 'const edge')
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_pair.h:1045:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator<(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1045 |     operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1045:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note:   'const edge' is not derived from 'const std::pair<_T1, _T2>'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:67:
/usr/include/c++/14/bits/stl_iterator.h:448:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  448 |     operator<(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:448:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note:   'const edge' is not derived from 'const std::reverse_iterator<_Iterator>'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:493:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  493 |     operator<(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:493:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note:   'const edge' is not derived from 'const std::reverse_iterator<_Iterator>'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:1694:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1694 |     operator<(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1694:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note:   'const edge' is not derived from 'const std::move_iterator<_IteratorL>'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:1760:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1760 |     operator<(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1760:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note:   'const edge' is not derived from 'const std::move_iterator<_IteratorL>'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~