Language: C++

#include <iostream>
#include <vector>
#include <string.h>
using namespace std;

struct data{
	int from;
	int to;
	int val;
};

struct point{
	vector<int> to;
	vector<int> val;
};

void init(point p[],data a[],int n){
	for(int i=1;i<=n;i++){
		p[i].to.clear();
		p[i].val.clear();
		a[i].from = a[i].to = a[i].val = 0;
	}
}

void search(point p[],int x,point tmp[],bool order,bool vis[]){
	vis[x] = true;
	for(int i=0;i<p[x].to.size();i++){
		if(order){
			tmp[x].to.push_back(p[x].to[i]);
			tmp[x].val.push_back(p[x].val[i]);
		}
		else{
			tmp[p[x].to[i]].to.push_back(x);
			tmp[p[x].to[i]].val.push_back(p[x].val[i]);
		}
		if(vis[p[x].to[i]] == false)
			search(p,p[x].to[i],tmp,order,vis);
	}
}

void make_edge(point p[],data a[],int x,int &index,bool vis[]){
	vis[x] = true;
	for(int i=0;i<p[x].to.size();i++){
		index++;
		a[index].from = x;
		a[index].to = p[x].to[i];
		a[index].val = p[x].val[i];
		if(vis[p[x].to[i]] == false)
			make_edge(p,a,p[x].to[i],index,vis);
	}
	
}

main(){
	int n,m,k,index,ifrom,ito,ival;
	int w[2510];
	bool b,vis[2510];
	data a[5010];
	point p[2510],tmp[2510];
	
	cin>>n>>m>>k;
	for(int i=1;i<=m;i++){
		cin>>ifrom>>ito>>ival;
		p[ito].to.push_back(ifrom);
		p[ito].val.push_back(ival);
	}
	
	memset(vis,0,sizeof(vis));
	search(p,n,tmp,0,vis);
	init(p,a,n);
	memset(vis,0,sizeof(vis));
	search(tmp,1,p,1,vis);
	memset(vis,0,sizeof(vis));
	make_edge(p,a,1,index,vis);
	/*
	cout<<index<<endl;
	for(int i=1;i<=index;i++){
		cout<<a[i].from<<" "<<a[i].to<<" "<<a[i].val<<endl;
	}
	*/
	for(int i=1;i<=n+1;i++){
		b = false;
		for(int j=1;j<=m;j++){
			if(w[a[j].to] < w[a[j].from] + a[j].val - k){
				b = true;
				w[a[j].to] = w[a[j].from] + a[j].val - k;
			}
		}
		if(b == false)
			break;
	}
	if(b)	cout<<-1;
	else	cout<<w[n]>0?w[n]:0;
	
}

Compiler output:
a.cc:17:21: error: reference to 'data' is ambiguous
   17 | void init(point p[],data a[],int n){
      |                     ^~~~
In file included from /usr/include/c++/14/string:53,
                 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/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:6:8: note:                 'struct data'
    6 | struct data{
      |        ^~~~
a.cc:17:21: error: 'data' has not been declared
   17 | void init(point p[],data a[],int n){
      |                     ^~~~
a.cc: In function 'void init(point*, int*, int)':
a.cc:21:22: error: request for member 'from' in '*(a + ((sizetype)(((long unsigned int)i) * 4)))', which is of non-class type 'int'
   21 |                 a[i].from = a[i].to = a[i].val = 0;
      |                      ^~~~
a.cc:21:34: error: request for member 'to' in '*(a + ((sizetype)(((long unsigned int)i) * 4)))', which is of non-class type 'int'
   21 |                 a[i].from = a[i].to = a[i].val = 0;
      |                                  ^~
a.cc:21:44: error: request for member 'val' in '*(a + ((sizetype)(((long unsigned int)i) * 4)))', which is of non-class type 'int'
   21 |                 a[i].from = a[i].to = a[i].val = 0;
      |                                            ^~~
a.cc: At global scope:
a.cc:41:26: error: reference to 'data' is ambiguous
   41 | void make_edge(point p[],data a[],int x,int &index,bool vis[]){
      |                          ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:6:8: note:                 'struct data'
    6 | struct data{
      |        ^~~~
a.cc:41:26: error: 'data' has not been declared
   41 | void make_edge(point p[],data a[],int x,int &index,bool vis[]){
      |                          ^~~~
a.cc: In function 'void make_edge(point*, int*, int, int&, bool*)':
a.cc:45:26: error: request for member 'from' in '*(a + ((sizetype)(((long unsigned int)index) * 4)))', which is of non-class type 'int'
   45 |                 a[index].from = x;
      |                          ^~~~
a.cc:46:26: error: request for member 'to' in '*(a + ((sizetype)(((long unsigned int)index) * 4)))', which is of non-class type 'int'
   46 |                 a[index].to = p[x].to[i];
      |                          ^~
a.cc:47:26: error: request for member 'val' in '*(a + ((sizetype)(((long unsigned int)index) * 4)))', which is of non-class type 'int'
   47 |                 a[index].val = p[x].val[i];
      |                          ^~~
a.cc: At global scope:
a.cc:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   54 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:58:9: error: reference to 'data' is ambiguous
   58 |         data a[5010];
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:6:8: note:                 'struct data'
    6 | struct data{
      |        ^~~~
a.cc:70:16: error: 'a' was not declared in this scope
   70 |         init(p,a,n);
      |                ^
a.cc:93:27: error: no match for 'operator>' (operand types are 'std::basic_ostream<char>' and 'int')
   93 |         else    cout<<w[n]>0?w[n]:0;
      |                 ~~~~~~~~~~^~
      |                     |      |
      |                     |      int
      |                     std::basic_ostream<char>
a.cc:93:27: note: candidate: 'operator>(int, int)' (built-in)
   93 |         else    cout<<w[n]>0?w[n]:0;
      |                 ~~~~~~~~~~^~
a.cc:93:27: note:   no known conversion for argument 1 from 'std::basic_ostream<char>' to 'int'
In file included from /usr/include/c++/14/string:48:
/usr/include/c++/14/bits/stl_iterator.h:462:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator>(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  462 |     operator>(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:462:5: note:   template argument deduction/substitution failed:
a.cc:93:28: note:   'std::basic_ostream<char>' is not derived from 'const std::reverse_iterator<_Iterator>'
   93 |         else    cout<<w[n]>0?w[n]:0;
      |                            ^
/usr/include/c++/14/bits/stl_iterator.h:507:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator>(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  507 |     operator>(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:507:5: note:   template argument deduction/substitution failed:
a.cc:93:28: note:   'std::basic_ostream<char>' is not derived from 'const std::reverse_iterator<_Iterator>'
   93 |         else    cout<<w[n]>0?w[n]:0;
      |                            ^
/usr/include/c++/14/bits/stl_iterator.h:1714:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator>(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1714 |     operator>(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1714:5: note:   template argument deduction/substitution failed:
a.cc:93:28: note:   'std::basic_ostream<char>' is not derived from 'const std::move_iterator<_IteratorL>'
   93 |         else    cout<<w[n]>0?w[n]:0;
      |                            ^
/usr/include/c++/14/bits/stl_iterator.h:1774:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator>(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1774 |     operator>(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1774:5: note:   template argument deduction/substitution failed:
a.cc:93:28: note:   'std::basic_ostream<char>' is not derived from 'const std::move_iterator<_IteratorL>'
   93 |         else    cout<<w[n]>0?w[n]:0;
      |                            ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/string:51:
/usr/include/c++/14/bits/stl_pair.h:1058:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator>(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1058 |     operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1058:5: note:   template argument deduction/substitution failed:
a.cc:93:28: note:   'std::basic_ostream<char>' is not derived from 'const std::pair<_T1, _T2>'
   93 |         else    cout<<w[n]>0?w[n]:0;
      |                            ^
In file included from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54:
/usr/include/c++/14/string_view:695:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator>(basic_string_view<_CharT, _Traits>, basic_string_view<_CharT, _Traits>)'
  695 |     operator> (basic_string_view<_CharT, _Traits> __x,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:695:5: note:   template argument deduction/substitution failed:
a.cc:93:28: note:   'std::basic_ostream<char>' is not derived from 'std::basic_string_view<_CharT, _Traits>'
   93 |         else    cout<<w[n]>0?w[n]:0;
      |                            ^
/usr/include/c++/14/string_view:702:5: note: candidate: 'template<class _Cha