Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int,int>
#define PP pair<P,P>
using namespace std;

int n,m,p;
vector<vector<int> > preki,preki2;
vector<int> visited,ex;

void dfs(int now){
    ex[now]++;
    visited[now]++;
    for(auto x : preki[now]){
        if(!visited[x]) dfs(x);
    }
}

void dfs2(int now){
    ex[now]++;
    visited[now]++;
    for(auto x : preki2[now]){
        if(!visited[x]) dfs2(x);
    }
}

int main(){
    cin >> n >> m >> p;
    map<P,int> cost;
    vector<vector<int> > prekiki(n);
    preki=preki2=prekiki;

    vector<int> exx(n,0);

    visited=exx;
    ex=exx;
    
    vector<P> sidelist;
    rep(i,m){
        int a,b,c; cin >> a >> b >> c;
        a--; b--;
        sidelist.push_back(P(a,b));
        preki[a].push_back(b);
        preki2[b].push_back(a);
        cost[P(a,b)]=-c+p;
    }
    dfs(0);
    visited=exx;
    dfs2(n-1);

    vector<P> ki;
/*
    rep(i,m){
        int a=sidelist[i].first;
        int b=sidelist[i].second;
        if(ex[a]>=2 && ex[b]>=2) ki.push_back(P(a,b));
    }
*/
    vector<int> ans(n,INF);
    ans[0]=0;

    bool update=true;
    int times=0;

    while(update){
        times++;
        update=false;
        rep(i,m){
            int res1=preki[i].first;
            int res2=preki[i].second;
            if(ex[res1]<2 | ex[res2]<2) continue;
            int newcost=ans[res1]+cost[preki[i]];
            if(ans[res2]>newcost){
                update=true;
                ans[res2]=newcost;
            }
        }
        if(times>n){
            cout << -1 << endl;
            return 0;
        }
    }

    if(ans[n-1]>0) ans[n-1]=0;
    cout << -ans[n-1] << endl;
return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:74:31: error: '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'class std::vector<int>'} has no member named 'first'
   74 |             int res1=preki[i].first;
      |                               ^~~~~
a.cc:75:31: error: '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'class std::vector<int>'} has no member named 'second'
   75 |             int res2=preki[i].second;
      |                               ^~~~~~
a.cc:77:39: error: no match for 'operator[]' (operand types are 'std::map<std::pair<int, int>, int>' and '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'})
   77 |             int newcost=ans[res1]+cost[preki[i]];
      |                                       ^
In file included from /usr/include/c++/14/map:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_map.h:504:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::pair<int, int>; _Tp = int; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >; mapped_type = int; key_type = std::pair<int, int>]'
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:504:34: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} to 'const std::map<std::pair<int, int>, int>::key_type&' {aka 'const std::pair<int, int>&'}
  504 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_map.h:524:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = std::pair<int, int>; _Tp = int; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >; mapped_type = int; key_type = std::pair<int, int>]'
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:524:29: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} to 'std::map<std::pair<int, int>, int>::key_type&&' {aka 'std::pair<int, int>&&'}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~