Language: C++

#include "bits/stdc++.h"

using namespace std;

void solve()
{
	long N, M, m = 0;
	cin >> N >> M;
	vector<long> adj[N];
	map<pair<long, long>, long> mp;
	for (long i = 0; i < M; i++)
	{
		long u, v, s;
		cin >> u >> v >> s;
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
		mp[{u, v}] = mp[{v, u}] = s;
		if (u == 0 || v == 0)
		{
			m = max(m, s);
		}
	}

	long ans = m-1;

	queue<long> q;
	vector<long> hi(N, -1), lo(N, -1);
	q.push(0);
	hi[0] = m-1, lo[0] = 1;

	while (!q.empty())
	{
		long v = q.front();
		q.pop();
		for (long nv : adj[v])
		{
			long ns = mp[{nv, v}];
			if (hi[nv] == -1)
			{
				hi[nv] = ns-lo[v];
				lo[nv] = max(1LL, ns-hi[v]);
				q.push(nv);
			}
			else
			{
				hi[nv] = min(hi[nv], ns-lo[v]);
				lo[nv] = max(lo[nv], ns-hi[v]);
			}
			long res = hi[nv]-lo[nv]+1;
			//cout << v << ' ' << nv << ' ' << hi[v] << ' ' << lo[v] << ' ' << hi[nv] << ' ' << lo[nv] << ' ' << res << endl;
			ans = min(ans, res);
		}
	}

	ans = max(ans, 0LL);

	cout << ans << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:42:45: error: no matching function for call to 'max(long long int, long int)'
   42 |                                 lo[nv] = max(1LL, ns-hi[v]);
      |                                          ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:42:45: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int')
   42 |                                 lo[nv] = max(1LL, ns-hi[v]);
      |                                          ~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:42:45: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   42 |                                 lo[nv] = max(1LL, ns-hi[v]);
      |                                          ~~~^~~~~~~~~~~~~~~
a.cc:56:18: error: no matching function for call to 'max(long int&, long long int)'
   56 |         ans = max(ans, 0LL);
      |               ~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:56:18: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   56 |         ans = max(ans, 0LL);
      |               ~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:56:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   56 |         ans = max(ans, 0LL);
      |               ~~~^~~~~~~~~~